diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-05 00:58:06 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-05 00:58:06 +0000 |
commit | a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4 (patch) | |
tree | f90c20acb5701e17d66fabfce5ca90c827ca9c2e | |
parent | bd205617c4f7eca4bb28c0343ed2f071189393c3 (diff) | |
download | chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.zip chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.tar.gz chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.tar.bz2 |
Add cross platform Widget::InitWithWidget(parent, const gfx::Rect& bounds);
On linux, native parent has to be either window_contents or widget depending of the type of wiget. InitWithWidget takes a parent Widget instead of native and hides these details.
I also cleaned up a few dead/duplicated code.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2355003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48990 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/login/screen_locker.cc | 10 | ||||
-rw-r--r-- | chrome/browser/find_bar_host_browsertest.cc | 18 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.cc | 2 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host_gtk.cc | 5 | ||||
-rw-r--r-- | chrome/browser/views/dropdown_bar_host_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 5 | ||||
-rw-r--r-- | views/examples/widget_example.h | 7 | ||||
-rw-r--r-- | views/view_unittest.cc | 7 | ||||
-rw-r--r-- | views/widget/widget.h | 7 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 15 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 4 | ||||
-rw-r--r-- | views/widget/widget_win.h | 1 |
15 files changed, 42 insertions, 51 deletions
diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 507f0fe..60540c7 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -181,11 +181,11 @@ void ScreenLocker::Init(const gfx::Rect& bounds) { lock_widget_ = new GrabWidget(); lock_widget_->MakeTransparent(); - lock_widget_->Init(lock_window_->window_contents(), - gfx::Rect((bounds.width() - size.width()) /2, - (bounds.height() - size.width()) /2, - size.width(), - size.height())); + lock_widget_->InitWithWidget(lock_window_, + gfx::Rect((bounds.width() - size.width()) / 2, + (bounds.height() - size.width()) / 2, + size.width(), + size.height())); lock_widget_->SetContentsView(screen_lock_view_); lock_widget_->Show(); screen_lock_view_->ClearAndSetFocusToPassword(); diff --git a/chrome/browser/find_bar_host_browsertest.cc b/chrome/browser/find_bar_host_browsertest.cc index 2473128..9ffaf72 100644 --- a/chrome/browser/find_bar_host_browsertest.cc +++ b/chrome/browser/find_bar_host_browsertest.cc @@ -732,23 +732,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, GURL url = server->TestServerPage(kSimplePage); ui_test_utils::NavigateToURL(browser(), url); -#if defined(OS_WIN) - // TODO(oshima): Windows code assumes that NativeView is - // assignable from NativeWindow, which is not true on other platforms. - // This has to be fixed, probably by having explicit - // GetNativeView / GetNativewWindow methods on BrowserWindow. - // See http://crbug.com/26873. - gfx::NativeView browser_view = browser()->window()->GetNativeHandle(); -#elif defined(OS_LINUX) - gfx::NativeView browser_view = - GTK_WIDGET(browser()->window()->GetNativeHandle()); -#else - // Mac does not use views. - NOTREACHED(); -#endif - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(browser_view); + views::FocusManager::GetFocusManagerForNativeWindow( + browser()->window()->GetNativeHandle()); // See where Escape is registered. views::Accelerator escape(base::VKEY_ESCAPE, false, false, false); diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc index b722979..4878e15 100644 --- a/chrome/browser/views/dropdown_bar_host.cc +++ b/chrome/browser/views/dropdown_bar_host.cc @@ -44,7 +44,7 @@ void DropdownBarHost::Init(DropdownBarView* view) { // Initialize the host. host_.reset(CreateHost()); - host_->Init(GetNativeView(browser_view_), gfx::Rect()); + host_->InitWithWidget(browser_view_->GetWidget(), gfx::Rect()); host_->SetContentsView(view_); // Start listening to focus changes, so we can register and unregister our diff --git a/chrome/browser/views/dropdown_bar_host.h b/chrome/browser/views/dropdown_bar_host.h index e77ffa5..8b45f06 100644 --- a/chrome/browser/views/dropdown_bar_host.h +++ b/chrome/browser/views/dropdown_bar_host.h @@ -141,9 +141,6 @@ class DropdownBarHost : public views::AcceleratorTarget, // Allows implementation to tweak widget position. void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); - // Returns the native view (is a child of the window widget in gtk). - gfx::NativeView GetNativeView(BrowserView* browser_view); - // Returns a keyboard event suitable for fowarding. NativeWebKeyboardEvent GetKeyboardEvent( const TabContents* contents, diff --git a/chrome/browser/views/dropdown_bar_host_gtk.cc b/chrome/browser/views/dropdown_bar_host_gtk.cc index 751d0d8..2a4e4be 100644 --- a/chrome/browser/views/dropdown_bar_host_gtk.cc +++ b/chrome/browser/views/dropdown_bar_host_gtk.cc @@ -24,11 +24,6 @@ void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, host_->Show(); } -gfx::NativeView DropdownBarHost::GetNativeView(BrowserView* browser_view) { - return static_cast<views::WidgetGtk*>( - browser_view->GetWidget())->window_contents(); -} - NativeWebKeyboardEvent DropdownBarHost::GetKeyboardEvent( const TabContents* contents, const views::Textfield::Keystroke& key_stroke) { diff --git a/chrome/browser/views/dropdown_bar_host_win.cc b/chrome/browser/views/dropdown_bar_host_win.cc index e5335dd..c14fb21 100644 --- a/chrome/browser/views/dropdown_bar_host_win.cc +++ b/chrome/browser/views/dropdown_bar_host_win.cc @@ -46,7 +46,3 @@ void DropdownBarHost::SetWidgetPositionNative(const gfx::Rect& new_pos, ::SetWindowPos(host_->GetNativeView(), HWND_TOP, new_pos.x(), new_pos.y(), new_pos.width(), new_pos.height(), swp_flags); } - -gfx::NativeView DropdownBarHost::GetNativeView(BrowserView* browser_view) { - return browser_view->GetWidget()->GetNativeView(); -} diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 230fcb6..41907af 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -338,9 +338,7 @@ void InfoBubble::Init(views::Widget* parent, #elif defined(OS_LINUX) MakeTransparent(); make_transient_to_parent(); - WidgetGtk::Init( - GTK_WIDGET(static_cast<WidgetGtk*>(parent)->GetNativeView()), - gfx::Rect()); + WidgetGtk::InitWithWidget(parent, gfx::Rect()); #if defined(OS_CHROMEOS) chromeos::WmIpc::instance()->SetWindowType( GetNativeView(), diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 857122a..77fb8eb 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -1010,16 +1010,13 @@ TabStrip::DropInfo::DropInfo(int drop_index, bool drop_before, bool point_down) arrow_window->set_window_style(WS_POPUP); arrow_window->set_window_ex_style(WS_EX_TOPMOST | WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT); - arrow_window->Init( - NULL, - gfx::Rect(0, 0, drop_indicator_width, drop_indicator_height)); #else arrow_window = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP); arrow_window->MakeTransparent(); +#endif arrow_window->Init( NULL, gfx::Rect(0, 0, drop_indicator_width, drop_indicator_height)); -#endif arrow_window->SetContentsView(arrow_view); } diff --git a/views/examples/widget_example.h b/views/examples/widget_example.h index 7546ba4..1897b53 100644 --- a/views/examples/widget_example.h +++ b/views/examples/widget_example.h @@ -128,15 +128,14 @@ class WidgetExample : public ExampleBase, public views::ButtonListener { widget->MakeTransparent(); // Compute where to place the child widget. // We'll place it at the center of the root widget. - views::WidgetGtk* parent_widget = - static_cast<views::WidgetGtk*>(parent->GetWidget()); + views::Widget* parent_widget = parent->GetWidget(); gfx::Rect bounds; parent_widget->GetBounds(&bounds, false); // Child widget is 200x200 square. bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, 200, 200); // Initialize the child widget with the computed bounds. - widget->Init(parent_widget->window_contents(), bounds); + widget->InitWithWidget(parent_widget, bounds); InitWidget(widget, transparency); } #endif @@ -155,7 +154,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener { point.Offset(0, parent->size().height()); gfx::Rect bounds(point.x(), point.y(), 200, 300); // Initialize the popup widget with the computed bounds. - widget->Init(NULL, bounds); + widget->InitWithWidget(parent->GetWidget(), bounds); InitWidget(widget, transparency); } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index ec9790a..b5e1091 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -637,11 +637,7 @@ TEST_F(ViewTest, Textfield) { Clipboard clipboard; Widget* window = CreateWidget(); -#if defined(OS_WIN) - static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); -#else - static_cast<WidgetGtk*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); -#endif + window->Init(NULL, gfx::Rect(0, 0, 100, 100)); RootView* root_view = window->GetRootView(); Textfield* textfield = new Textfield(); @@ -1353,4 +1349,3 @@ TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { test.CheckChangingHierarhy(); #endif } - diff --git a/views/widget/widget.h b/views/widget/widget.h index d4ddcfc..cf893ee 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -97,6 +97,13 @@ class Widget { // contents as the window is sized. virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) = 0; + // Initialize the widget with a views::Widget parent and an initial + // desired size. This internally invokes |Init(gfx::NativeView, + // const gfx::Rect&)| but it determines the correct native view + // for each platform and the type of widget. Passing NULL to + // |parent| is same as invoking |Init(NULL, bounds)|. + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds) = 0; + // Returns the WidgetDelegate for delegating certain events. virtual WidgetDelegate* GetWidgetDelegate() = 0; diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 055c855..78137c5 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -456,6 +456,21 @@ void WidgetGtk::ActiveWindowChanged(GdkWindow* active_window) { //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, Widget implementation: +void WidgetGtk::InitWithWidget(Widget* parent, + const gfx::Rect& bounds) { + WidgetGtk* parent_gtk = static_cast<WidgetGtk*>(parent); + GtkWidget* native_parent = NULL; + if (parent != NULL) { + if (type_ != TYPE_CHILD) { + // window's parent has to be window. + native_parent = parent_gtk->GetNativeView(); + } else { + native_parent = parent_gtk->window_contents(); + } + } + Init(native_parent, bounds); +} + void WidgetGtk::Init(GtkWidget* parent, const gfx::Rect& bounds) { if (type_ != TYPE_CHILD) diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 980baaf..beb629f 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -152,6 +152,7 @@ class WidgetGtk // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); virtual WidgetDelegate* GetWidgetDelegate(); virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 2b4c649..72431b0 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -170,6 +170,10 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { ImmAssociateContextEx(hwnd(), NULL, 0); } +void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { + Init(parent->GetNativeView(), bounds); +} + WidgetDelegate* WidgetWin::GetWidgetDelegate() { return delegate_; } diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index f5ac2d1..e0cdc44d 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -181,6 +181,7 @@ class WidgetWin : public app::WindowImpl, // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); virtual WidgetDelegate* GetWidgetDelegate(); virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); |