1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be found 3 // in the LICENSE file. 4 5 #include "libcef/browser/views/view_adapter.h" 6 7 #include "libcef/browser/chrome/views/toolbar_view_impl.h" 8 #include "libcef/browser/views/basic_label_button_impl.h" 9 #include "libcef/browser/views/basic_panel_impl.h" 10 #include "libcef/browser/views/browser_view_impl.h" 11 #include "libcef/browser/views/menu_button_impl.h" 12 #include "libcef/browser/views/scroll_view_impl.h" 13 #include "libcef/browser/views/textfield_impl.h" 14 #include "libcef/browser/views/view_util.h" 15 #include "libcef/browser/views/window_impl.h" 16 17 // static GetFor(CefRefPtr<CefView> view)18CefViewAdapter* CefViewAdapter::GetFor(CefRefPtr<CefView> view) { 19 CefViewAdapter* adapter = nullptr; 20 if (view->AsBrowserView()) { 21 adapter = static_cast<CefBrowserViewImpl*>(view->AsBrowserView().get()); 22 } else if (view->AsButton()) { 23 CefRefPtr<CefButton> button = view->AsButton(); 24 if (button->AsLabelButton()) { 25 CefRefPtr<CefLabelButton> label_button = button->AsLabelButton(); 26 if (label_button->AsMenuButton()) { 27 adapter = 28 static_cast<CefMenuButtonImpl*>(label_button->AsMenuButton().get()); 29 } else { 30 adapter = static_cast<CefBasicLabelButtonImpl*>(label_button.get()); 31 } 32 } 33 } else if (view->AsPanel()) { 34 CefRefPtr<CefPanel> panel = view->AsPanel(); 35 if (panel->AsWindow()) { 36 adapter = static_cast<CefWindowImpl*>(panel->AsWindow().get()); 37 } else { 38 adapter = static_cast<CefBasicPanelImpl*>(panel.get()); 39 } 40 } else if (view->AsScrollView()) { 41 adapter = static_cast<CefScrollViewImpl*>(view->AsScrollView().get()); 42 } else if (view->AsTextfield()) { 43 adapter = static_cast<CefTextfieldImpl*>(view->AsTextfield().get()); 44 } else if (view->GetTypeString().ToString() == 45 CefToolbarViewImpl::kTypeString) { 46 adapter = static_cast<CefToolbarViewImpl*>(view.get()); 47 } 48 49 DCHECK(adapter); 50 return adapter; 51 } 52 53 // static GetFor(views::View * view)54CefViewAdapter* CefViewAdapter::GetFor(views::View* view) { 55 CefRefPtr<CefView> cef_view = view_util::GetFor(view, false); 56 if (cef_view) 57 return GetFor(cef_view); 58 return nullptr; 59 } 60