diff options
Diffstat (limited to 'chrome/browser/ui/views')
68 files changed, 1679 insertions, 1371 deletions
diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index d724051..5ae9cc8 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -117,8 +117,35 @@ class OptInButtonBorder : public views::Border { DISALLOW_COPY_AND_ASSIGN(OptInButtonBorder); }; +gfx::NativeView GetRelativeWindowForPopup(gfx::NativeView edit_native_view) { +#if defined(OS_WIN) + // When an IME is attached to the rich-edit control, retrieve its window + // handle and show this popup window under the IME windows. + // Otherwise, show this popup window under top-most windows. + // TODO(hbono): http://b/1111369 if we exclude this popup window from the + // display area of IME windows, this workaround becomes unnecessary. + HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); + return ime_window ? ime_window : HWND_NOTOPMOST; +#elif defined(TOOLKIT_USES_GTK) + GtkWidget* toplevel = gtk_widget_get_toplevel(edit_native_view); + DCHECK(GTK_WIDGET_TOPLEVEL(toplevel)); + return toplevel; +#endif +} + } // namespace +class AutocompletePopupContentsView::AutocompletePopupWidget + : public views::Widget, + public base::SupportsWeakPtr<AutocompletePopupWidget> { + public: + AutocompletePopupWidget() {} + virtual ~AutocompletePopupWidget() {} + + private: + DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWidget); +}; + class AutocompletePopupContentsView::InstantOptInView : public views::View, public views::ButtonListener { @@ -328,16 +355,16 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { if (popup_ == NULL) { // If the popup is currently closed, we need to create it. - popup_ = (new AutocompletePopupClass)->AsWeakPtr(); + popup_ = (new AutocompletePopupWidget)->AsWeakPtr(); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.can_activate = false; params.transparent = true; params.parent = location_bar_->GetWidget()->GetNativeView(); params.bounds = GetPopupBounds(); - popup_->GetWidget()->Init(params); + popup_->Init(params); popup_->SetContentsView(this); - popup_->MoveAbove(popup_->GetRelativeWindowForPopup( - omnibox_view_->GetNativeView())); + popup_->MoveAbove( + GetRelativeWindowForPopup(omnibox_view_->GetNativeView())); popup_->Show(); } else { // Animate the popup shrinking, but don't animate growing larger since that diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h index 7673bf0..f862fbe 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h @@ -16,12 +16,6 @@ #include "views/view.h" #include "webkit/glue/window_open_disposition.h" -#if defined(OS_WIN) -#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_win.h" -#elif defined(TOOLKIT_USES_GTK) -#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.h" -#endif - class AutocompleteEditModel; struct AutocompleteMatch; class AutocompleteResultView; @@ -105,11 +99,7 @@ class AutocompletePopupContentsView : public views::View, views::View* opt_in_view_; private: -#if defined(OS_WIN) - typedef AutocompletePopupWin AutocompletePopupClass; -#elif defined(TOOLKIT_USES_GTK) - typedef AutocompletePopupGtk AutocompletePopupClass; -#endif + class AutocompletePopupWidget; class InstantOptInView; // Returns true if the model has a match at the specified index. @@ -148,7 +138,7 @@ class AutocompletePopupContentsView : public views::View, // when its window is destroyed. This is a WeakPtr because it's possible for // the OS to destroy the window and thus delete this object before we're // deleted, or without our knowledge. - base::WeakPtr<AutocompletePopupClass> popup_; + base::WeakPtr<AutocompletePopupWidget> popup_; // The edit view that invokes us. OmniboxView* omnibox_view_; diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc deleted file mode 100644 index d0299a8..0000000 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.cc +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.h" - -#include "chrome/browser/ui/gtk/gtk_util.h" - -//////////////////////////////////////////////////////////////////////////////// -// AutocompletePopupGtk, public: - -AutocompletePopupGtk::AutocompletePopupGtk() { -} - -AutocompletePopupGtk::~AutocompletePopupGtk() { -} - -gfx::NativeView AutocompletePopupGtk::GetRelativeWindowForPopup( - gfx::NativeView edit_native_view) const { - GtkWidget* toplevel = gtk_widget_get_toplevel(edit_native_view); - DCHECK(GTK_WIDGET_TOPLEVEL(toplevel)); - return toplevel; -} diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.h b/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.h deleted file mode 100644 index ba07afc..0000000 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_gtk.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_ -#define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_ -#pragma once - -#include "base/memory/weak_ptr.h" -#include "views/widget/widget_gtk.h" - -class AutocompletePopupGtk - : public views::WidgetGtk, - public base::SupportsWeakPtr<AutocompletePopupGtk> { - public: - // Creates the popup and shows it. |edit_view| is the edit that created us. - AutocompletePopupGtk(); - virtual ~AutocompletePopupGtk(); - - // Returns the window the popup should be relative to. |edit_native_view| is - // the native view of the autocomplete edit. - gfx::NativeView GetRelativeWindowForPopup( - gfx::NativeView edit_native_view) const; - - private: - DISALLOW_COPY_AND_ASSIGN(AutocompletePopupGtk); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_GTK_H_ diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.cc deleted file mode 100644 index 37dbf1e..0000000 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/autocomplete/autocomplete_popup_win.h" - -//////////////////////////////////////////////////////////////////////////////// -// AutocompletePopupWin, public: - -AutocompletePopupWin::AutocompletePopupWin() { -} - -AutocompletePopupWin::~AutocompletePopupWin() { -} - -gfx::NativeView AutocompletePopupWin::GetRelativeWindowForPopup( - gfx::NativeView edit_native_view) const { - // When an IME is attached to the rich-edit control, retrieve its window - // handle and show this popup window under the IME windows. - // Otherwise, show this popup window under top-most windows. - // TODO(hbono): http://b/1111369 if we exclude this popup window from the - // display area of IME windows, this workaround becomes unnecessary. - HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); - return ime_window ? ime_window : HWND_NOTOPMOST; -} diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.h b/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.h deleted file mode 100644 index 2f369e2..0000000 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_win.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_WIN_H_ -#define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_WIN_H_ -#pragma once - -#include "base/memory/weak_ptr.h" -#include "views/widget/widget_win.h" - -class AutocompletePopupWin - : public views::WidgetWin, - public base::SupportsWeakPtr<AutocompletePopupWin> { - public: - // Creates the popup and shows it. |edit_view| is the edit that created us. - AutocompletePopupWin(); - virtual ~AutocompletePopupWin(); - - // Returns the window the popup should be relative to. |edit_native_view| is - // the native view of the autocomplete edit. - gfx::NativeView GetRelativeWindowForPopup( - gfx::NativeView edit_native_view) const; - - private: - DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWin); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_WIN_H_ diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index 997327f..f6103bd 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -1361,7 +1361,7 @@ class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(button->state() == views::CustomButton::BS_PUSHED); // Close the window. - window_->CloseWindow(); + window_->Close(); window_ = NULL; } }; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 1a960db..912a5b9 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -346,7 +346,7 @@ std::wstring BookmarkBubbleView::accessible_name() { void BookmarkBubbleView::Close() { ApplyEdits(); - static_cast<Bubble*>(GetWidget())->Close(); + GetWidget()->Close(); } void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { @@ -387,7 +387,8 @@ void BookmarkBubbleView::ShowEditor() { ShowWindow(GetWidget()->GetNativeView(), SW_HIDE); #elif defined(TOOLKIT_USES_GTK) gfx::NativeWindow parent = GTK_WINDOW( - static_cast<views::WidgetGtk*>(GetWidget())->GetTransientParent()); + static_cast<views::WidgetGtk*>(GetWidget()->native_widget())-> + GetTransientParent()); #endif // Even though we just hid the window, we need to invoke Close to schedule diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc index b8e25ef..4690ce0 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc @@ -237,7 +237,7 @@ void BookmarkEditorView::Show(HWND parent_hwnd) { void BookmarkEditorView::Close() { DCHECK(window()); - window()->CloseWindow(); + window()->Close(); } void BookmarkEditorView::ShowContextMenuForView(View* source, @@ -391,7 +391,7 @@ void BookmarkEditorView::BookmarkNodeRemoved(BookmarkModel* model, details_.existing_node->HasAncestor(node)) || (parent_ && parent_->HasAncestor(node))) { // The node, or its parent was removed. Close the dialog. - window()->CloseWindow(); + window()->Close(); } else { Reset(); } diff --git a/chrome/browser/ui/views/browser_bubble.cc b/chrome/browser/ui/views/browser_bubble.cc index 53541d7..d87180d 100644 --- a/chrome/browser/ui/views/browser_bubble.cc +++ b/chrome/browser/ui/views/browser_bubble.cc @@ -18,7 +18,7 @@ BrowserBubbleHost* GetBubbleHostFromFrame(views::Widget* frame) { return NULL; BrowserBubbleHost* bubble_host = NULL; - views::Window* window = frame->GetWindow(); + views::Window* window = frame->GetContainingWindow(); if (window) { bubble_host = BrowserView::GetBrowserViewForNativeWindow( window->GetNativeWindow()); @@ -38,7 +38,6 @@ BrowserBubble::BrowserBubble(views::View* view, view_(view), relative_to_(relative_to), arrow_location_(arrow_location), - visible_(false), delegate_(NULL), attached_(false), bubble_host_(GetBubbleHostFromFrame(frame)) { @@ -94,7 +93,7 @@ void BrowserBubble::BrowserWindowMoved() { delegate_->BubbleBrowserWindowMoved(this); else Hide(); - if (visible_) + if (popup_->IsVisible()) Reposition(); } @@ -144,3 +143,9 @@ void BrowserBubble::SetAbsoluteBounds(const gfx::Rect& window_bounds) { SetBounds(relative_origin.x(), relative_origin.y(), window_bounds.width(), window_bounds.height()); } + +void BrowserBubble::MovePopup(int x, int y, int w, int h) { + popup_->SetBounds(gfx::Rect(x, y, w, h)); +} + + diff --git a/chrome/browser/ui/views/browser_bubble.h b/chrome/browser/ui/views/browser_bubble.h index 64eb87e..c74d40b 100644 --- a/chrome/browser/ui/views/browser_bubble.h +++ b/chrome/browser/ui/views/browser_bubble.h @@ -73,7 +73,6 @@ class BrowserBubble { // Show or hide the bubble. virtual void Show(bool activate); virtual void Hide(); - bool visible() const { return visible_; } // The contained view. views::View* view() const { return view_; } @@ -127,9 +126,6 @@ class BrowserBubble { // The bounds relative to the frame. gfx::Rect bounds_; - // Current visibility. - bool visible_; - // The delegate isn't owned by the bubble. Delegate* delegate_; diff --git a/chrome/browser/ui/views/browser_bubble_gtk.cc b/chrome/browser/ui/views/browser_bubble_gtk.cc index bf905ed..4339e05 100644 --- a/chrome/browser/ui/views/browser_bubble_gtk.cc +++ b/chrome/browser/ui/views/browser_bubble_gtk.cc @@ -23,7 +23,8 @@ namespace { class BubbleWidget : public views::WidgetGtk { public: BubbleWidget(BrowserBubble* bubble, const gfx::Insets& content_margins) - : bubble_(bubble), + : views::WidgetGtk(new views::Widget), + bubble_(bubble), border_contents_(new BorderContents) { border_contents_->Init(); border_contents_->set_content_margins(content_margins); @@ -47,7 +48,7 @@ class BubbleWidget : public views::WidgetGtk { } virtual void Hide() { - if (IsActive()&& bubble_) { + if (IsActive() && bubble_) { BrowserBubble::Delegate* delegate = bubble_->delegate(); if (delegate) delegate->BubbleLostFocus(bubble_, false); @@ -92,18 +93,19 @@ class BubbleWidget : public views::WidgetGtk { void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { // TODO(port) - BubbleWidget* pop = new BubbleWidget(this, content_margins); - pop->MakeTransparent(); - pop->make_transient_to_parent(); + BubbleWidget* bubble_widget = new BubbleWidget(this, content_margins); + popup_ = bubble_widget->GetWidget(); views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); + params.transparent = true; params.parent = frame_->GetNativeView(); - pop->Init(params); + params.native_widget = bubble_widget; + popup_->Init(params); #if defined(OS_CHROMEOS) { vector<int> params; params.push_back(0); // don't show while screen is locked chromeos::WmIpc::instance()->SetWindowType( - pop->GetNativeView(), + popup_->GetNativeView(), chromeos::WM_IPC_WINDOW_CHROME_INFO_BUBBLE, ¶ms); } @@ -115,42 +117,32 @@ void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { // that when |contents| gets added, it will already have a widget, and thus // any NativeButtons it creates in ViewHierarchyChanged() will be functional // (e.g. calling SetChecked() on checkboxes is safe). - pop->SetContentsView(contents_view); + popup_->SetContentsView(contents_view); // Added border_contents before |view_| so it will paint under it. - contents_view->AddChildView(pop->border_contents()); + contents_view->AddChildView(bubble_widget->border_contents()); contents_view->AddChildView(view_); - popup_ = pop; - ResizeToView(); Reposition(); AttachToBrowser(); } -void BrowserBubble::MovePopup(int x, int y, int w, int h) { - views::WidgetGtk* pop = static_cast<views::WidgetGtk*>(popup_); - pop->SetBounds(gfx::Rect(x, y, w, h)); -} - void BrowserBubble::Show(bool activate) { - if (visible_) - return; - static_cast<BubbleWidget*>(popup_)->ShowAndActivate(activate); - visible_ = true; + if (!popup_->IsVisible()) { + static_cast<BubbleWidget*>(popup_->native_widget())->ShowAndActivate( + activate); + } } void BrowserBubble::Hide() { - if (!visible_) - return; - views::WidgetGtk* pop = static_cast<views::WidgetGtk*>(popup_); - pop->Hide(); - visible_ = false; + if (popup_->IsVisible()) + static_cast<BubbleWidget*>(popup_->native_widget())->Hide(); } void BrowserBubble::ResizeToView() { BorderContents* border_contents = - static_cast<BubbleWidget*>(popup_)->border_contents(); + static_cast<BubbleWidget*>(popup_->native_widget())->border_contents(); // Calculate and set the bounds for all windows and views. gfx::Rect window_bounds; diff --git a/chrome/browser/ui/views/browser_bubble_win.cc b/chrome/browser/ui/views/browser_bubble_win.cc index 3effe25..ce4b66c 100644 --- a/chrome/browser/ui/views/browser_bubble_win.cc +++ b/chrome/browser/ui/views/browser_bubble_win.cc @@ -14,7 +14,8 @@ class BubbleWidget : public views::WidgetWin { public: explicit BubbleWidget(BrowserBubble* bubble) - : bubble_(bubble), + : views::WidgetWin(new views::Widget), + bubble_(bubble), border_widget_(new BorderWidgetWin) { set_window_style(WS_POPUP | WS_CLIPCHILDREN); set_window_ex_style(WS_EX_TOOLWINDOW); @@ -108,17 +109,18 @@ class BubbleWidget : public views::WidgetWin { void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { // popup_ is a Widget, but we need to do some WidgetWin stuff first, then // we'll assign it into popup_. - BubbleWidget* pop = new BubbleWidget(this); - popup_ = pop; + BubbleWidget* bubble_widget = new BubbleWidget(this); - BorderWidgetWin* border_widget = pop->border_widget(); + BorderWidgetWin* border_widget = bubble_widget->border_widget(); border_widget->InitBorderWidgetWin(new BorderContents, frame_->GetNativeView()); border_widget->border_contents()->set_content_margins(content_margins); + popup_ = bubble_widget->GetWidget(); // We make the BorderWidgetWin the owner of the Bubble HWND, so that the // latter is displayed on top of the former. views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); + params.native_widget = bubble_widget; params.parent = border_widget->GetNativeView(); popup_->Init(params); popup_->SetContentsView(view_); @@ -128,30 +130,21 @@ void BrowserBubble::InitPopup(const gfx::Insets& content_margins) { AttachToBrowser(); } -void BrowserBubble::MovePopup(int x, int y, int w, int h) { - views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_); - pop->SetBounds(gfx::Rect(x, y, w, h)); -} - void BrowserBubble::Show(bool activate) { - if (visible_) - return; - BubbleWidget* pop = static_cast<BubbleWidget*>(popup_); - pop->ShowAndActivate(activate); - visible_ = true; + if (!popup_->IsVisible()) { + static_cast<BubbleWidget*>(popup_->native_widget())->ShowAndActivate( + activate); + } } void BrowserBubble::Hide() { - if (!visible_) - return; - views::WidgetWin* pop = static_cast<views::WidgetWin*>(popup_); - pop->Hide(); - visible_ = false; + if (popup_->IsVisible()) + static_cast<BubbleWidget*>(popup_->native_widget())->Hide(); } void BrowserBubble::ResizeToView() { BorderWidgetWin* border_widget = - static_cast<BubbleWidget*>(popup_)->border_widget(); + static_cast<BubbleWidget*>(popup_->native_widget())->border_widget(); gfx::Rect window_bounds; window_bounds = border_widget->SizeAndGetBounds(GetAbsoluteRelativeTo(), diff --git a/chrome/browser/ui/views/bubble/border_widget_win.cc b/chrome/browser/ui/views/bubble/border_widget_win.cc index 2fd2fc7..8c72485 100644 --- a/chrome/browser/ui/views/bubble/border_widget_win.cc +++ b/chrome/browser/ui/views/bubble/border_widget_win.cc @@ -7,9 +7,11 @@ #include <windows.h> #include "chrome/browser/ui/views/bubble/border_contents.h" +#include "views/widget/widget.h" BorderWidgetWin::BorderWidgetWin() - : border_contents_(NULL) { + : views::WidgetWin(new views::Widget), + border_contents_(NULL) { } void BorderWidgetWin::InitBorderWidgetWin(BorderContents* border_contents, @@ -21,8 +23,9 @@ void BorderWidgetWin::InitBorderWidgetWin(BorderContents* border_contents, views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.parent = owner; + params.native_widget = this; GetWidget()->Init(params); - SetContentsView(border_contents_); + GetWidget()->SetContentsView(border_contents_); SetWindowPos(owner, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOREDRAW); } @@ -37,7 +40,7 @@ gfx::Rect BorderWidgetWin::SizeAndGetBounds( border_contents_->SizeAndGetBounds(position_relative_to, arrow_location, false, contents_size, &contents_bounds, &window_bounds); - SetBounds(window_bounds); + GetWidget()->SetBounds(window_bounds); // Return |contents_bounds| in screen coordinates. contents_bounds.Offset(window_bounds.origin()); diff --git a/chrome/browser/ui/views/bubble/bubble.cc b/chrome/browser/ui/views/bubble/bubble.cc index 87b47d7..2f0b46d 100644 --- a/chrome/browser/ui/views/bubble/bubble.cc +++ b/chrome/browser/ui/views/bubble/bubble.cc @@ -121,6 +121,11 @@ void Bubble::AnimationProgressed(const ui::Animation* animation) { Bubble::Bubble() : +#if defined(OS_WIN) + views::WidgetWin(new views::Widget), +#elif defined(TOOLKIT_USES_GTK) + views::WidgetGtk(new views::Widget), +#endif #if defined(TOOLKIT_USES_GTK) border_contents_(NULL), #elif defined(OS_WIN) @@ -129,7 +134,7 @@ Bubble::Bubble() delegate_(NULL), show_status_(kOpen), fade_away_on_close_(false), -#if defined(OS_LINUX) +#if defined(TOOLKIT_USES_GTK) type_(views::Widget::InitParams::TYPE_WINDOW), #endif #if defined(OS_CHROMEOS) @@ -142,7 +147,8 @@ Bubble::Bubble() #if defined(OS_CHROMEOS) Bubble::Bubble(views::Widget::InitParams::Type type, bool show_while_screen_is_locked) - : border_contents_(NULL), + : views::WidgetGtk(new views::Widget), + border_contents_(NULL), delegate_(NULL), show_status_(kOpen), fade_away_on_close_(false), @@ -168,7 +174,7 @@ void Bubble::InitBubble(views::Widget* parent, // Create the main window. #if defined(OS_WIN) - views::Window* parent_window = parent->GetWindow(); + views::Window* parent_window = parent->GetContainingWindow(); if (parent_window) parent_window->DisableInactiveRendering(); set_window_style(WS_POPUP | WS_CLIPCHILDREN); @@ -185,7 +191,7 @@ void Bubble::InitBubble(views::Widget* parent, if (fade_in) { border_->SetOpacity(0); - SetOpacity(0); + GetWidget()->SetOpacity(0); } border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView()); @@ -195,6 +201,7 @@ void Bubble::InitBubble(views::Widget* parent, // latter is displayed on top of the former. views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.parent = border_->GetNativeView(); + params.native_widget = this; GetWidget()->Init(params); SetWindowText(GetNativeView(), delegate_->accessible_name().c_str()); @@ -202,8 +209,7 @@ void Bubble::InitBubble(views::Widget* parent, views::Widget::InitParams params(type_); params.transparent = true; params.parent_widget = parent; - // TODO(beng): Figure out how to make this implicit or set via InitParams. - make_transient_to_parent(); + params.native_widget = this; GetWidget()->Init(params); #if defined(OS_CHROMEOS) { @@ -223,7 +229,7 @@ void Bubble::InitBubble(views::Widget* parent, // that when |contents| gets added, it will already have a widget, and thus // any NativeButtons it creates in ViewHierarchyChanged() will be functional // (e.g. calling SetChecked() on checkboxes is safe). - SetContentsView(contents_view); + GetWidget()->SetContentsView(contents_view); // Adding |contents| as a child has to be done before we call // contents->GetPreferredSize() below, since some supplied views don't // actually initialize themselves until they're added to a hierarchy. @@ -262,10 +268,10 @@ void Bubble::InitBubble(views::Widget* parent, gfx::Rect(gfx::Point(), window_bounds.size())); contents->SetBoundsRect(contents_bounds); #endif - SetBounds(window_bounds); + GetWidget()->SetBounds(window_bounds); // Register the Escape accelerator for closing. - GetFocusManager()->RegisterAccelerator( + GetWidget()->GetFocusManager()->RegisterAccelerator( views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); // Done creating the bubble. @@ -280,7 +286,7 @@ void Bubble::InitBubble(views::Widget* parent, if (fade_in) FadeIn(); #elif defined(TOOLKIT_USES_GTK) - views::WidgetGtk::Show(); + GetWidget()->Show(); #endif } @@ -307,23 +313,23 @@ void Bubble::SizeToContents() { gfx::Rect(gfx::Point(), window_bounds.size())); contents_->SetBoundsRect(contents_bounds); #endif - SetBounds(window_bounds); + GetWidget()->SetBounds(window_bounds); } #if defined(OS_WIN) void Bubble::OnActivate(UINT action, BOOL minimized, HWND window) { // The popup should close when it is deactivated. if (action == WA_INACTIVE) { - Close(); + GetWidget()->Close(); } else if (action == WA_ACTIVE) { - DCHECK(GetRootView()->has_children()); - GetRootView()->GetChildViewAt(0)->RequestFocus(); + DCHECK(GetWidget()->GetRootView()->has_children()); + GetWidget()->GetRootView()->GetChildViewAt(0)->RequestFocus(); } } #elif defined(TOOLKIT_USES_GTK) void Bubble::IsActiveChanged() { - if (!IsActive()) - Close(); + if (!GetWidget()->IsActive()) + GetWidget()->Close(); } #endif @@ -331,13 +337,15 @@ void Bubble::DoClose(bool closed_by_escape) { if (show_status_ == kClosed) return; - GetFocusManager()->UnregisterAccelerator( + GetWidget()->GetFocusManager()->UnregisterAccelerator( views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); if (delegate_) delegate_->BubbleClosing(this, closed_by_escape); show_status_ = kClosed; #if defined(OS_WIN) border_->Close(); +#endif +#if defined(OS_WIN) WidgetWin::Close(); #elif defined(TOOLKIT_USES_GTK) WidgetGtk::Close(); diff --git a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc index fd71a09..c39a093 100644 --- a/chrome/browser/ui/views/constrained_html_delegate_gtk.cc +++ b/chrome/browser/ui/views/constrained_html_delegate_gtk.cc @@ -70,7 +70,8 @@ class ConstrainedHtmlDelegateGtk : public views::WidgetGtk, ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( Profile* profile, HtmlDialogUIDelegate* delegate) - : HtmlDialogTabContentsDelegate(profile), + : views::WidgetGtk(new views::Widget), + HtmlDialogTabContentsDelegate(profile), html_tab_contents_(profile, NULL, MSG_ROUTING_NONE, NULL, NULL), tab_container_(NULL), html_delegate_(delegate), @@ -86,10 +87,11 @@ ConstrainedHtmlDelegateGtk::ConstrainedHtmlDelegateGtk( PageTransition::START_PAGE); views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; GetWidget()->Init(params); tab_container_ = new TabContentsContainer; - SetContentsView(tab_container_); + GetWidget()->SetContentsView(tab_container_); tab_container_->ChangeTabContents(&html_tab_contents_); gfx::Size dialog_size; diff --git a/chrome/browser/ui/views/constrained_window_views.cc b/chrome/browser/ui/views/constrained_window_views.cc index 8034744..ef8f72c 100644 --- a/chrome/browser/ui/views/constrained_window_views.cc +++ b/chrome/browser/ui/views/constrained_window_views.cc @@ -576,8 +576,11 @@ ConstrainedWindowViews::ConstrainedWindowViews( NativeConstrainedWindow::CreateNativeConstrainedWindow(this))) { GetWindow()->non_client_view()->SetFrameView(CreateFrameViewForWindow()); views::Window::InitParams params(window_delegate); + params.native_window = native_constrained_window_->AsNativeWindow(); params.widget_init_params.child = true; params.widget_init_params.parent = owner->GetNativeView(); + params.widget_init_params.native_widget = + native_constrained_window_->AsNativeWindow()->AsNativeWidget(); GetWindow()->InitWindow(params); } @@ -608,7 +611,7 @@ void ConstrainedWindowViews::CloseConstrainedWindow() { NotificationService::current()->Notify(NotificationType::CWINDOW_CLOSED, Source<ConstrainedWindow>(this), NotificationService::NoDetails()); - GetWindow()->CloseWindow(); + GetWindow()->Close(); } void ConstrainedWindowViews::FocusConstrainedWindow() { @@ -621,6 +624,13 @@ void ConstrainedWindowViews::FocusConstrainedWindow() { } //////////////////////////////////////////////////////////////////////////////// +// ConstrainedWindowViews, views::Window overrides: + +views::NonClientFrameView* ConstrainedWindowViews::CreateFrameViewForWindow() { + return new ConstrainedWindowFrameView(this); +} + +//////////////////////////////////////////////////////////////////////////////// // ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation: void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() { @@ -633,10 +643,12 @@ void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { GetWindow()->Activate(); } -views::NonClientFrameView* ConstrainedWindowViews::CreateFrameViewForWindow() { - return new ConstrainedWindowFrameView(this); +views::internal::NativeWindowDelegate* + ConstrainedWindowViews::AsNativeWindowDelegate() { + return this; } + //////////////////////////////////////////////////////////////////////////////// // ConstrainedWindow, public: diff --git a/chrome/browser/ui/views/constrained_window_views.h b/chrome/browser/ui/views/constrained_window_views.h index 98d1047..c09740c 100644 --- a/chrome/browser/ui/views/constrained_window_views.h +++ b/chrome/browser/ui/views/constrained_window_views.h @@ -10,11 +10,15 @@ #include "content/browser/tab_contents/constrained_window.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" +#include "views/window/window.h" class ConstrainedTabContentsWindowDelegate; class ConstrainedWindowAnimation; class ConstrainedWindowFrameView; namespace views { +namespace internal { +class NativeWindowDelegate; +} class NativeWindow; class NonClientFrameView; class Window; @@ -35,6 +39,8 @@ class NativeConstrainedWindowDelegate { // Creates the frame view for the constrained window. // TODO(beng): remove once ConstrainedWindowViews is-a views::Window. virtual views::NonClientFrameView* CreateFrameViewForWindow() = 0; + + virtual views::internal::NativeWindowDelegate* AsNativeWindowDelegate() = 0; }; class NativeConstrainedWindow { @@ -54,7 +60,8 @@ class NativeConstrainedWindow { // A ConstrainedWindow implementation that implements a Constrained Window as // a child HWND with a custom window frame. // -class ConstrainedWindowViews : public ConstrainedWindow, +class ConstrainedWindowViews : public views::Window, + public ConstrainedWindow, public NativeConstrainedWindowDelegate { public: ConstrainedWindowViews(TabContents* owner, @@ -72,10 +79,14 @@ class ConstrainedWindowViews : public ConstrainedWindow, virtual void FocusConstrainedWindow() OVERRIDE; private: + // Overridden from views::Window: + virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; + // Overridden from NativeConstrainedWindowDelegate: virtual void OnNativeConstrainedWindowDestroyed() OVERRIDE; virtual void OnNativeConstrainedWindowMouseActivate() OVERRIDE; - virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; + virtual views::internal::NativeWindowDelegate* + AsNativeWindowDelegate() OVERRIDE; // The TabContents that owns and constrains this ConstrainedWindow. TabContents* owner_; diff --git a/chrome/browser/ui/views/dom_view_browsertest.cc b/chrome/browser/ui/views/dom_view_browsertest.cc index f78b549..00bf748 100644 --- a/chrome/browser/ui/views/dom_view_browsertest.cc +++ b/chrome/browser/ui/views/dom_view_browsertest.cc @@ -14,7 +14,7 @@ using views::Widget; class DOMViewTest : public InProcessBrowserTest { public: Widget* CreatePopupWindow() { - Widget* widget = Widget::CreateWidget(); + Widget* widget = new Widget; Widget::InitParams params(Widget::InitParams::TYPE_POPUP); params.bounds = gfx::Rect(0, 0, 400, 400); widget->Init(params); diff --git a/chrome/browser/ui/views/download/download_started_animation_win.cc b/chrome/browser/ui/views/download/download_started_animation_win.cc index 91099a0..f38a5b2 100644 --- a/chrome/browser/ui/views/download/download_started_animation_win.cc +++ b/chrome/browser/ui/views/download/download_started_animation_win.cc @@ -101,14 +101,14 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin( SetImage(kDownloadImage); - popup_ = views::Widget::CreateWidget(); - popup_->SetOpacity(0x00); + popup_ = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; params.parent = tab_contents_->GetNativeView(); popup_->Init(params); + popup_->SetOpacity(0x00); popup_->SetContentsView(this); Reposition(); popup_->Show(); diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc index 9675589..d2313f0 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.cc +++ b/chrome/browser/ui/views/dropdown_bar_host.cc @@ -61,7 +61,7 @@ void DropdownBarHost::Init(views::View* view, delegate_ = delegate; // Initialize the host. - host_.reset(views::Widget::CreateWidget()); + host_.reset(new views::Widget); views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); params.delete_on_destroy = false; params.parent_widget = browser_view_->GetWidget(); diff --git a/chrome/browser/ui/views/extensions/extension_popup.cc b/chrome/browser/ui/views/extensions/extension_popup.cc index aa7888b..723b4d6 100644 --- a/chrome/browser/ui/views/extensions/extension_popup.cc +++ b/chrome/browser/ui/views/extensions/extension_popup.cc @@ -77,11 +77,11 @@ ExtensionPopup::~ExtensionPopup() { } void ExtensionPopup::Show(bool activate) { - if (visible()) + if (popup_->IsVisible()) return; #if defined(OS_WIN) - frame_->GetWindow()->DisableInactiveRendering(); + frame_->GetContainingWindow()->DisableInactiveRendering(); #endif ResizeToView(); diff --git a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc index 17cd52b..5834ba7 100644 --- a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc +++ b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc @@ -56,7 +56,13 @@ class FindInPageTest : public InProcessBrowserTest { } // namespace -IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { +#if defined(TOOLKIT_USES_GTK) +#define MAYBE_CrashEscHandlers FLAKY_CrashEscHandlers +#else +#define MAYBE_CrashEscHandlers CrashEscHandlers +#endif + +IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_CrashEscHandlers) { ASSERT_TRUE(test_server()->Start()); // First we navigate to our test page (tab A). diff --git a/chrome/browser/ui/views/find_bar_host_win.cc b/chrome/browser/ui/views/find_bar_host_win.cc index 69edc15..f30702c 100644 --- a/chrome/browser/ui/views/find_bar_host_win.cc +++ b/chrome/browser/ui/views/find_bar_host_win.cc @@ -20,7 +20,8 @@ void FindBarHost::AudibleAlert() { void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) { RECT frame_rect = {0}, webcontents_rect = {0}; ::GetWindowRect( - static_cast<views::WidgetWin*>(host())->GetParent(), &frame_rect); + static_cast<views::WidgetWin*>(host()->native_widget())->GetParent(), + &frame_rect); ::GetWindowRect( find_bar_controller_-> tab_contents()->tab_contents()->view()->GetNativeView(), diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index 7db2137..2e0a390 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -491,7 +491,7 @@ FirstRunBubble* FirstRunBubble::Show(Profile* profile, bubble->set_view(view); bubble->InitBubble( parent, position_relative_to, arrow_location, view, bubble); - bubble->GetFocusManager()->AddFocusChangeListener(view); + bubble->GetWidget()->GetFocusManager()->AddFocusChangeListener(view); view->BubbleShown(); return bubble; } @@ -504,7 +504,7 @@ FirstRunBubble::FirstRunBubble() FirstRunBubble::~FirstRunBubble() { enable_window_method_factory_.RevokeAll(); - GetFocusManager()->RemoveFocusChangeListener(view_); + GetWidget()->GetFocusManager()->RemoveFocusChangeListener(view_); } void FirstRunBubble::EnableParent() { @@ -517,7 +517,7 @@ void FirstRunBubble::EnableParent() { views::NativeWidget* parent = views::NativeWidget::GetNativeWidgetForNativeView(GetParent()); if (parent) - parent->GetWidget()->GetWindow()->DisableInactiveRendering(); + parent->GetWidget()->GetContainingWindow()->DisableInactiveRendering(); // Reactivate the FirstRunBubble so it responds to OnActivate messages. SetWindowPos(GetParent(), 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW | SWP_SHOWWINDOW); diff --git a/chrome/browser/ui/views/first_run_search_engine_view.cc b/chrome/browser/ui/views/first_run_search_engine_view.cc index 58f8beb..386e41b 100644 --- a/chrome/browser/ui/views/first_run_search_engine_view.cc +++ b/chrome/browser/ui/views/first_run_search_engine_view.cc @@ -74,7 +74,7 @@ void ShowFirstRunDialog(Profile* profile, window->Show(); views::AcceleratorHandler accelerator_handler; MessageLoopForUI::current()->Run(&accelerator_handler); - window->CloseWindow(); + window->Close(); } } // namespace first_run diff --git a/chrome/browser/ui/views/frame/app_panel_browser_frame_view.cc b/chrome/browser/ui/views/frame/app_panel_browser_frame_view.cc index 86032fc..3f25d88 100644 --- a/chrome/browser/ui/views/frame/app_panel_browser_frame_view.cc +++ b/chrome/browser/ui/views/frame/app_panel_browser_frame_view.cc @@ -146,15 +146,14 @@ int AppPanelBrowserFrameView::NonClientHitTest(const gfx::Point& point) { if (!bounds().Contains(point)) return HTNOWHERE; - int frame_component = - frame_->GetWindow()->client_view()->NonClientHitTest(point); + int frame_component = frame_->client_view()->NonClientHitTest(point); // See if we're in the sysmenu region. (We check the ClientView first to be // consistent with OpaqueBrowserFrameView; it's not really necessary here.) gfx::Rect sysmenu_rect(IconBounds()); // In maximized mode we extend the rect to the screen corner to take advantage // of Fitts' Law. - if (frame_->GetWindow()->IsMaximized()) + if (frame_->IsMaximized()) sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); if (sysmenu_rect.Contains(point)) @@ -171,7 +170,7 @@ int AppPanelBrowserFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, NonClientBorderThickness(), NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, - frame_->GetWindow()->window_delegate()->CanResize()); + frame_->window_delegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -180,7 +179,7 @@ void AppPanelBrowserFrameView::GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) { DCHECK(window_mask); - if (frame_->GetWindow()->IsMaximized()) + if (frame_->IsMaximized()) return; // Redefine the window visible region for the new size. @@ -219,13 +218,12 @@ void AppPanelBrowserFrameView::UpdateWindowIcon() { // AppPanelBrowserFrameView, views::View overrides: void AppPanelBrowserFrameView::OnPaint(gfx::Canvas* canvas) { - views::Window* window = frame_->GetWindow(); - if (window->IsMaximized()) + if (frame_->IsMaximized()) PaintMaximizedFrameBorder(canvas); else PaintRestoredFrameBorder(canvas); PaintTitleBar(canvas); - if (!window->IsMaximized()) + if (!frame_->IsMaximized()) PaintRestoredClientEdge(canvas); } @@ -241,7 +239,7 @@ void AppPanelBrowserFrameView::Layout() { void AppPanelBrowserFrameView::ButtonPressed(views::Button* sender, const views::Event& event) { if (sender == close_button_) - frame_->GetWindow()->CloseWindow(); + frame_->Close(); } /////////////////////////////////////////////////////////////////////////////// @@ -256,19 +254,19 @@ bool AppPanelBrowserFrameView::ShouldTabIconViewAnimate() const { } SkBitmap AppPanelBrowserFrameView::GetFaviconForTabIconView() { - return frame_->GetWindow()->window_delegate()->GetWindowIcon(); + return frame_->window_delegate()->GetWindowIcon(); } /////////////////////////////////////////////////////////////////////////////// // AppPanelBrowserFrameView, private: int AppPanelBrowserFrameView::FrameBorderThickness() const { - return frame_->GetWindow()->IsMaximized() ? 0 : kFrameBorderThickness; + return frame_->IsMaximized() ? 0 : kFrameBorderThickness; } int AppPanelBrowserFrameView::NonClientBorderThickness() const { return FrameBorderThickness() + - (frame_->GetWindow()->IsMaximized() ? 0 : kClientEdgeThickness); + (frame_->IsMaximized() ? 0 : kClientEdgeThickness); } int AppPanelBrowserFrameView::NonClientTopBorderHeight() const { @@ -279,7 +277,7 @@ int AppPanelBrowserFrameView::NonClientTopBorderHeight() const { int AppPanelBrowserFrameView::TitlebarBottomThickness() const { return kTitlebarTopAndBottomEdgeThickness + - (frame_->GetWindow()->IsMaximized() ? 0 : kClientEdgeThickness); + (frame_->IsMaximized() ? 0 : kClientEdgeThickness); } int AppPanelBrowserFrameView::IconSize() const { @@ -303,7 +301,7 @@ gfx::Rect AppPanelBrowserFrameView::IconBounds() const { // with restored windows, so when the window is restored, instead of // calculating the remaining space from below the frame border, we calculate // from below the top border-plus-padding. - int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ? + int unavailable_px_at_top = frame_->IsMaximized() ? frame_thickness : kTitlebarTopAndBottomEdgeThickness; // When the icon is shorter than the minimum space we reserve for the caption // button, we vertically center it. We want to bias rounding to put extra @@ -401,13 +399,13 @@ void AppPanelBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { SkBitmap* titlebar_bottom = rb.GetBitmapNamed(IDR_APP_TOP_CENTER); int edge_height = titlebar_bottom->height() - kClientEdgeThickness; canvas->TileImageInt(*titlebar_bottom, 0, - frame_->GetWindow()->client_view()->y() - edge_height, + frame_->client_view()->y() - edge_height, width(), edge_height); } void AppPanelBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) { // The window icon is painted by the TabIconView. - views::WindowDelegate* d = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* d = frame_->window_delegate(); canvas->DrawStringInt(d->GetWindowTitle(), BrowserFrame::GetTitleFont(), SK_ColorBLACK, GetMirroredXForRect(title_bounds_), title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); @@ -467,7 +465,7 @@ void AppPanelBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { void AppPanelBrowserFrameView::LayoutWindowControls() { close_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, views::ImageButton::ALIGN_BOTTOM); - bool is_maximized = frame_->GetWindow()->IsMaximized(); + bool is_maximized = frame_->IsMaximized(); // There should always be the same number of non-border pixels visible to the // side of the close button. In maximized mode we extend the button to the // screen corner to obey Fitts' Law. diff --git a/chrome/browser/ui/views/frame/browser_frame.cc b/chrome/browser/ui/views/frame/browser_frame.cc index 94d0fa7..0b0842e 100644 --- a/chrome/browser/ui/views/frame/browser_frame.cc +++ b/chrome/browser/ui/views/frame/browser_frame.cc @@ -4,23 +4,53 @@ #include "chrome/browser/ui/views/frame/browser_frame.h" +#include "base/command_line.h" +#include "chrome/browser/themes/theme_service.h" +#include "chrome/browser/themes/theme_service_factory.h" +#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" #include "chrome/browser/ui/views/frame/browser_root_view.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/native_browser_frame.h" +#include "chrome/common/chrome_switches.h" +#include "ui/base/theme_provider.h" #include "views/widget/native_widget.h" #include "views/widget/widget.h" #include "views/window/native_window.h" #include "views/window/window.h" +#if defined(OS_WIN) +#include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" +#endif + //////////////////////////////////////////////////////////////////////////////// // BrowserFrame, public: +BrowserFrame::BrowserFrame(BrowserView* browser_view) + : native_browser_frame_(NULL), + root_view_(NULL), + browser_frame_view_(NULL), + browser_view_(browser_view) { + browser_view_->set_frame(this); + set_is_secondary_widget(false); +} + BrowserFrame::~BrowserFrame() { } -views::Window* BrowserFrame::GetWindow() { - return native_browser_frame_->AsNativeWindow()->GetWindow(); +void BrowserFrame::InitBrowserFrame() { + native_browser_frame_ = + NativeBrowserFrame::CreateNativeBrowserFrame(this, browser_view_); + views::Window::InitParams params(browser_view_); + params.native_window = native_browser_frame_->AsNativeWindow(); + params.widget_init_params.native_widget = + params.native_window->AsNativeWidget(); + InitWindow(params); +#if defined(OS_CHROMEOS) + // On ChromeOS we always want top-level windows to appear active. + if (!browser_view_->IsBrowserTypePopup()) + DisableInactiveRendering(); +#endif } int BrowserFrame::GetMinimizeButtonOffset() const { @@ -39,12 +69,20 @@ void BrowserFrame::UpdateThrobber(bool running) { browser_frame_view_->UpdateThrobber(running); } -ui::ThemeProvider* BrowserFrame::GetThemeProviderForFrame() const { - return native_browser_frame_->GetThemeProviderForFrame(); -} - bool BrowserFrame::AlwaysUseNativeFrame() const { - return native_browser_frame_->AlwaysUseNativeFrame(); + // App panel windows draw their own frame. + if (browser_view_->IsBrowserTypePanel()) + return false; + + // We don't theme popup or app windows, so regardless of whether or not a + // theme is active for normal browser windows, we don't want to use the custom + // frame for popups/apps. + if (!browser_view_->IsBrowserTypeNormal() && ShouldUseNativeFrame()) + return true; + + // Otherwise, we use the native frame when we're told we should by the theme + // provider (e.g. no custom theme is active). + return GetThemeProvider()->ShouldUseNativeFrame(); } views::View* BrowserFrame::GetFrameView() const { @@ -52,32 +90,68 @@ views::View* BrowserFrame::GetFrameView() const { } void BrowserFrame::TabStripDisplayModeChanged() { + if (GetRootView()->has_children()) { + // Make sure the child of the root view gets Layout again. + GetRootView()->GetChildViewAt(0)->InvalidateLayout(); + } + GetRootView()->Layout(); native_browser_frame_->TabStripDisplayModeChanged(); } -//////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, NativeBrowserFrameDelegate implementation: +/////////////////////////////////////////////////////////////////////////////// +// BrowserFrameWin, views::Window overrides: + +bool BrowserFrame::IsMaximized() const { +#if defined(OS_CHROMEOS) + if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeosFrame)) { + return !IsFullscreen() && + (!browser_view_->IsBrowserTypePopup() || Window::IsMaximized()); + } +#endif + return Window::IsMaximized(); +} -views::RootView* BrowserFrame::DelegateCreateRootView() { +views::RootView* BrowserFrame::CreateRootView() { root_view_ = new BrowserRootView( browser_view_, native_browser_frame_->AsNativeWindow()->AsNativeWidget()->GetWidget()); return root_view_; } -views::NonClientFrameView* BrowserFrame::DelegateCreateFrameViewForWindow() { - browser_frame_view_ = - native_browser_frame_->CreateBrowserNonClientFrameView(); +views::NonClientFrameView* BrowserFrame::CreateFrameViewForWindow() { +#if defined(OS_WIN) + if (AlwaysUseNativeFrame()) { + browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_); + } else { +#endif + browser_frame_view_ = + browser::CreateBrowserNonClientFrameView(this, browser_view_); +#if defined(OS_WIN) + } +#endif return browser_frame_view_; } +bool BrowserFrame::GetAccelerator(int command_id, + ui::Accelerator* accelerator) { + return browser_view_->GetAccelerator(command_id, accelerator); +} -//////////////////////////////////////////////////////////////////////////////// -// BrowserFrame, protected: +ThemeProvider* BrowserFrame::GetThemeProvider() const { + return ThemeServiceFactory::GetForProfile( + browser_view_->browser()->profile()); +} -BrowserFrame::BrowserFrame(BrowserView* browser_view) - : native_browser_frame_(NULL), - root_view_(NULL), - browser_frame_view_(NULL), - browser_view_(browser_view) { +void BrowserFrame::OnNativeWindowActivationChanged(bool active) { + if (active) { + // When running under remote desktop, if the remote desktop client is not + // active on the users desktop, then none of the windows contained in the + // remote desktop will be activated. However, WindowWin::Activate will + // still bring this browser window to the foreground. We explicitly set + // ourselves as the last active browser window to ensure that we get treated + // as such by the rest of Chrome. + BrowserList::SetLastActive(browser_view_->browser()); + } + Window::OnNativeWindowActivationChanged(active); } + diff --git a/chrome/browser/ui/views/frame/browser_frame.h b/chrome/browser/ui/views/frame/browser_frame.h index 2a7ae13..2c07fd2 100644 --- a/chrome/browser/ui/views/frame/browser_frame.h +++ b/chrome/browser/ui/views/frame/browser_frame.h @@ -10,6 +10,7 @@ #include "base/logging.h" #include "build/build_config.h" #include "chrome/browser/ui/views/frame/native_browser_frame_delegate.h" +#include "views/window/window.h" class AeroGlassNonClientView; class BrowserNonClientFrameView; @@ -34,19 +35,15 @@ class Window; } // This is a virtual interface that allows system specific browser frames. -class BrowserFrame : public NativeBrowserFrameDelegate { +class BrowserFrame : public views::Window { public: + explicit BrowserFrame(BrowserView* browser_view); virtual ~BrowserFrame(); - // Creates the appropriate BrowserFrame for this platform. The returned - // object is owned by the caller. - static BrowserFrame* Create(BrowserView* browser_view, Profile* profile); - static const gfx::Font& GetTitleFont(); - // Returns the Window associated with this frame. Guaranteed non-NULL after - // construction. - views::Window* GetWindow(); + // Initialize the frame (creates the underlying native window). + void InitBrowserFrame(); // Determine the distance of the left edge of the minimize button from the // left edge of the window. Used in our Non-Client View's Layout. @@ -64,9 +61,6 @@ class BrowserFrame : public NativeBrowserFrameDelegate { // Tells the frame to update the throbber. void UpdateThrobber(bool running); - // Returns the theme provider for this frame. - ui::ThemeProvider* GetThemeProviderForFrame() const; - // Returns true if the window should use the native frame view. This is true // if there are no themes applied on Vista, or if there are themes applied and // this browser window is an app or popup. @@ -79,19 +73,14 @@ class BrowserFrame : public NativeBrowserFrameDelegate { // its frame treatment if necessary. void TabStripDisplayModeChanged(); - protected: - // Overridden from NativeBrowserFrameDelegate: - virtual views::RootView* DelegateCreateRootView() OVERRIDE; - virtual views::NonClientFrameView* DelegateCreateFrameViewForWindow() - OVERRIDE; - - // TODO(beng): Temporarily provided as a way to associate the subclass' - // implementation of NativeBrowserFrame with this. - void set_native_browser_frame(NativeBrowserFrame* native_browser_frame) { - native_browser_frame_ = native_browser_frame; - } - - explicit BrowserFrame(BrowserView* browser_view); + // Overridden from views::Window: + virtual bool IsMaximized() const OVERRIDE; + virtual views::RootView* CreateRootView() OVERRIDE; + virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; + virtual bool GetAccelerator(int command_id, + ui::Accelerator* accelerator) OVERRIDE; + virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE; + virtual void OnNativeWindowActivationChanged(bool active) OVERRIDE; private: NativeBrowserFrame* native_browser_frame_; diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.cc b/chrome/browser/ui/views/frame/browser_frame_gtk.cc index 110c599..dd1cee8 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.cc +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.cc @@ -17,38 +17,23 @@ #include "views/widget/root_view.h" #include "views/window/hit_test.h" -#if !defined(OS_CHROMEOS) -// static (Factory method.) -BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, - Profile* profile) { - BrowserFrameGtk* frame = new BrowserFrameGtk(browser_view, profile); - frame->InitBrowserFrame(); - return frame; -} -#endif - // static const gfx::Font& BrowserFrame::GetTitleFont() { static gfx::Font *title_font = new gfx::Font(); return *title_font; } -BrowserFrameGtk::BrowserFrameGtk(BrowserView* browser_view, Profile* profile) - : BrowserFrame(browser_view), - ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), +BrowserFrameGtk::BrowserFrameGtk(BrowserFrame* browser_frame, + BrowserView* browser_view) + : views::WindowGtk(browser_frame), browser_view_(browser_view) { - set_native_browser_frame(this); - browser_view_->set_frame(this); + // Don't focus anything on creation, selecting a tab will set the focus. + set_focus_on_creation(false); } BrowserFrameGtk::~BrowserFrameGtk() { } -void BrowserFrameGtk::InitBrowserFrame() { - WindowGtk::GetWindow()->InitWindow(views::Window::InitParams(browser_view_)); - // Don't focus anything on creation, selecting a tab will set the focus. -} - //////////////////////////////////////////////////////////////////////////////// // BrowserFrameGtk, NativeBrowserFrame implementation: @@ -60,58 +45,22 @@ const views::NativeWindow* BrowserFrameGtk::AsNativeWindow() const { return this; } -BrowserNonClientFrameView* BrowserFrameGtk::CreateBrowserNonClientFrameView() { - return browser::CreateBrowserNonClientFrameView(this, browser_view_); -} - int BrowserFrameGtk::GetMinimizeButtonOffset() const { NOTIMPLEMENTED(); return 0; } -ThemeProvider* BrowserFrameGtk::GetThemeProviderForFrame() const { - // This is implemented for a different interface than GetThemeProvider is, - // but they mean the same things. - return GetThemeProvider(); -} - -bool BrowserFrameGtk::AlwaysUseNativeFrame() const { - return false; -} - void BrowserFrameGtk::TabStripDisplayModeChanged() { - if (GetRootView()->has_children()) { + if (GetWidget()->GetRootView()->has_children()) { // Make sure the child of the root view gets Layout again. - GetRootView()->GetChildViewAt(0)->InvalidateLayout(); + GetWidget()->GetRootView()->GetChildViewAt(0)->InvalidateLayout(); } - GetRootView()->Layout(); + GetWidget()->GetRootView()->Layout(); } //////////////////////////////////////////////////////////////////////////////// // BrowserFrameGtk, WindowGtk overrides : -ThemeProvider* BrowserFrameGtk::GetThemeProvider() const { - return ThemeServiceFactory::GetForProfile( - browser_view_->browser()->profile()); -} - -void BrowserFrameGtk::SetInitialFocus() { - browser_view_->RestoreFocus(); -} - -views::RootView* BrowserFrameGtk::CreateRootView() { - return delegate_->DelegateCreateRootView(); -} - -bool BrowserFrameGtk::GetAccelerator(int cmd_id, - ui::Accelerator* accelerator) { - return browser_view_->GetAccelerator(cmd_id, accelerator); -} - -views::NonClientFrameView* BrowserFrameGtk::CreateFrameViewForWindow() { - return delegate_->DelegateCreateFrameViewForWindow(); -} - gboolean BrowserFrameGtk::OnWindowStateEvent(GtkWidget* widget, GdkEventWindowState* event) { bool was_full_screen = IsFullscreen(); @@ -132,3 +81,15 @@ gboolean BrowserFrameGtk::OnConfigureEvent(GtkWidget* widget, browser_view_->WindowMoved(); return views::WindowGtk::OnConfigureEvent(widget, event); } + + +//////////////////////////////////////////////////////////////////////////////// +// NativeBrowserFrame, public: + +// static +NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( + BrowserFrame* browser_frame, + BrowserView* browser_view) { + return new BrowserFrameGtk(browser_frame, browser_view); +} + diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.h b/chrome/browser/ui/views/frame/browser_frame_gtk.h index 14536a1..a499496 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.h +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.h @@ -14,46 +14,27 @@ class BrowserNonClientFrameView; class BrowserRootView; -class BrowserFrameGtk : public BrowserFrame, - public views::WindowGtk, +class BrowserFrameGtk : public views::WindowGtk, public NativeBrowserFrame { public: // Normally you will create this class by calling BrowserFrame::Create. // Init must be called before using this class, which Create will do for you. - BrowserFrameGtk(BrowserView* browser_view, Profile* profile); + BrowserFrameGtk(BrowserFrame* browser_frame, BrowserView* browser_view); virtual ~BrowserFrameGtk(); - // Creates a frame view and initializes the window. This - // initialization function must be called after construction, it is - // separate to avoid recursive calling of the frame from its - // constructor. - virtual void InitBrowserFrame(); - protected: // Overridden from NativeBrowserFrame: virtual views::NativeWindow* AsNativeWindow() OVERRIDE; virtual const views::NativeWindow* AsNativeWindow() const OVERRIDE; - virtual BrowserNonClientFrameView* CreateBrowserNonClientFrameView() OVERRIDE; virtual int GetMinimizeButtonOffset() const OVERRIDE; - virtual ui::ThemeProvider* GetThemeProviderForFrame() const OVERRIDE; - virtual bool AlwaysUseNativeFrame() const OVERRIDE; virtual void TabStripDisplayModeChanged() OVERRIDE; // Overridden from views::WindowGtk: - virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE; - virtual void SetInitialFocus() OVERRIDE; - virtual views::RootView* CreateRootView(); - virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); - virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; virtual gboolean OnWindowStateEvent(GtkWidget* widget, GdkEventWindowState* event); virtual gboolean OnConfigureEvent(GtkWidget* widget, GdkEventConfigure* event); - BrowserView* browser_view() const { - return browser_view_; - } - private: NativeBrowserFrameDelegate* delegate_; diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 49e14db..1982d43 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -10,19 +10,13 @@ #include <set> #include "chrome/browser/accessibility/browser_accessibility_state.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/themes/theme_service.h" -#include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/browser_list.h" -#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" #include "chrome/browser/ui/views/frame/browser_view.h" -#include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" #include "grit/theme_resources.h" #include "ui/gfx/font.h" #include "views/screen.h" -#include "views/widget/root_view.h" -#include "views/widget/widget_win.h" -#include "views/window/window_win.h" +#include "views/window/non_client_view.h" +#include "views/window/window.h" // static static const int kClientEdgeThickness = 3; @@ -33,26 +27,14 @@ static const int kDWMFrameTopOffset = 3; // If not -1, windows are shown with this state. static int explicit_show_state = -1; -// static (Factory method.) -BrowserFrame* BrowserFrame::Create(BrowserView* browser_view, - Profile* profile) { - BrowserFrame* frame = new BrowserFrameWin(browser_view, profile); - - views::Window::InitParams params(browser_view); - frame->GetWindow()->InitWindow(params); - return frame; -} - /////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin, public: -BrowserFrameWin::BrowserFrameWin(BrowserView* browser_view, Profile* profile) - : BrowserFrame(browser_view), +BrowserFrameWin::BrowserFrameWin(BrowserFrame* browser_frame, + BrowserView* browser_view) + : views::WindowWin(browser_frame), browser_view_(browser_view), - ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)) { - set_native_browser_frame(this); - browser_view_->set_frame(this); - non_client_view()->SetFrameView(CreateFrameViewForWindow()); + browser_frame_(browser_frame) { // Don't focus anything on creation, selecting a tab will set the focus. set_focus_on_creation(false); } @@ -82,7 +64,7 @@ int BrowserFrameWin::GetShowState() const { gfx::Insets BrowserFrameWin::GetClientAreaInsets() const { // Use the default client insets for an opaque frame or a glass popup/app // frame. - if (!non_client_view()->UseNativeFrame() || + if (!GetWindow()->non_client_view()->UseNativeFrame() || !browser_view_->IsBrowserTypeNormal()) { return WindowWin::GetClientAreaInsets(); } @@ -97,9 +79,11 @@ gfx::Insets BrowserFrameWin::GetClientAreaInsets() const { return gfx::Insets(0, border_thickness, border_thickness, border_thickness); } -bool BrowserFrameWin::GetAccelerator(int cmd_id, - ui::Accelerator* accelerator) { - return browser_view_->GetAccelerator(cmd_id, accelerator); +void BrowserFrameWin::UpdateFrameAfterFrameChange() { + // We need to update the glass region on or off before the base class adjusts + // the window region. + UpdateDWMFrame(); + WindowWin::UpdateFrameAfterFrameChange(); } void BrowserFrameWin::OnEndSession(BOOL ending, UINT logoff) { @@ -125,51 +109,16 @@ void BrowserFrameWin::OnWindowPosChanged(WINDOWPOS* window_pos) { // SWP_SHOWWINDOW, however callers typically are careful about not specifying // this flag unless necessary to avoid flicker. if (window_pos->flags & SWP_SHOWWINDOW) { - non_client_view()->Layout(); - non_client_view()->SchedulePaint(); + GetWindow()->non_client_view()->Layout(); + GetWindow()->non_client_view()->SchedulePaint(); } } -ThemeProvider* BrowserFrameWin::GetThemeProvider() const { - return ThemeServiceFactory::GetForProfile( - browser_view_->browser()->profile()); -} - void BrowserFrameWin::OnScreenReaderDetected() { BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); WindowWin::OnScreenReaderDetected(); } -/////////////////////////////////////////////////////////////////////////////// -// BrowserFrameWin, views::Window overrides: - -void BrowserFrameWin::Activate() { - // When running under remote desktop, if the remote desktop client is not - // active on the users desktop, then none of the windows contained in the - // remote desktop will be activated. However, WindowWin::Activate will still - // bring this browser window to the foreground. We explicitly set ourselves - // as the last active browser window to ensure that we get treated as such by - // the rest of Chrome. - BrowserList::SetLastActive(browser_view_->browser()); - - WindowWin::Activate(); -} - -void BrowserFrameWin::UpdateFrameAfterFrameChange() { - // We need to update the glass region on or off before the base class adjusts - // the window region. - UpdateDWMFrame(); - WindowWin::UpdateFrameAfterFrameChange(); -} - -views::RootView* BrowserFrameWin::CreateRootView() { - return delegate_->DelegateCreateRootView(); -} - -views::NonClientFrameView* BrowserFrameWin::CreateFrameViewForWindow() { - return delegate_->DelegateCreateFrameViewForWindow(); -} - //////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin, NativeBrowserFrame implementation: @@ -181,12 +130,6 @@ const views::NativeWindow* BrowserFrameWin::AsNativeWindow() const { return this; } -BrowserNonClientFrameView* BrowserFrameWin::CreateBrowserNonClientFrameView() { - if (AlwaysUseNativeFrame()) - return new GlassBrowserFrameView(this, browser_view_); - return browser::CreateBrowserNonClientFrameView(this, browser_view_); -} - int BrowserFrameWin::GetMinimizeButtonOffset() const { TITLEBARINFOEX titlebar_info; titlebar_info.cbSize = sizeof(TITLEBARINFOEX); @@ -199,36 +142,7 @@ int BrowserFrameWin::GetMinimizeButtonOffset() const { return minimize_button_corner.x; } -ui::ThemeProvider* BrowserFrameWin::GetThemeProviderForFrame() const { - // This is implemented for a different interface than GetThemeProvider is, - // but they mean the same things. - return GetThemeProvider(); -} - -bool BrowserFrameWin::AlwaysUseNativeFrame() const { - // App panel windows draw their own frame. - if (browser_view_->IsBrowserTypePanel() && browser_view_->IsBrowserTypeApp()) - return false; - - // We don't theme popup or app windows, so regardless of whether or not a - // theme is active for normal browser windows, we don't want to use the custom - // frame for popups/apps. - if (!browser_view_->IsBrowserTypeNormal() && - views::WidgetWin::IsAeroGlassEnabled()) - return true; - - // Otherwise, we use the native frame when we're told we should by the theme - // provider (e.g. no custom theme is active). - return GetThemeProvider()->ShouldUseNativeFrame(); -} - void BrowserFrameWin::TabStripDisplayModeChanged() { - if (GetRootView()->has_children()) { - // Make sure the child of the root view gets Layout again. - GetRootView()->GetChildViewAt(0)->InvalidateLayout(); - } - GetRootView()->Layout(); - UpdateDWMFrame(); } @@ -237,7 +151,7 @@ void BrowserFrameWin::TabStripDisplayModeChanged() { void BrowserFrameWin::UpdateDWMFrame() { // Nothing to do yet, or we're not showing a DWM frame. - if (!client_view() || !AlwaysUseNativeFrame()) + if (!GetWindow()->client_view() || !browser_frame_->AlwaysUseNativeFrame()) return; MARGINS margins = { 0 }; @@ -255,7 +169,7 @@ void BrowserFrameWin::UpdateDWMFrame() { // borders. if (!browser_view_->IsFullscreen()) { gfx::Rect tabstrip_bounds( - GetBoundsForTabStrip(browser_view_->tabstrip())); + browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); margins.cyTopHeight = (browser_view_->UseVerticalTabs() ? tabstrip_bounds.y() : tabstrip_bounds.bottom()) + kDWMFrameTopOffset; } @@ -275,3 +189,13 @@ const gfx::Font& BrowserFrame::GetTitleFont() { return *title_font; } +//////////////////////////////////////////////////////////////////////////////// +// NativeBrowserFrame, public: + +// static +NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( + BrowserFrame* browser_frame, + BrowserView* browser_view) { + return new BrowserFrameWin(browser_frame, browser_view); +} + diff --git a/chrome/browser/ui/views/frame/browser_frame_win.h b/chrome/browser/ui/views/frame/browser_frame_win.h index c49f380..d7249f4 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.h +++ b/chrome/browser/ui/views/frame/browser_frame_win.h @@ -12,7 +12,6 @@ #include "views/window/window_win.h" class BrowserView; -class Profile; /////////////////////////////////////////////////////////////////////////////// // BrowserFrameWin @@ -20,13 +19,10 @@ class Profile; // BrowserFrame is a WindowWin subclass that provides the window frame for the // Chrome browser window. // -class BrowserFrameWin : public BrowserFrame, - public views::WindowWin, +class BrowserFrameWin : public views::WindowWin, public NativeBrowserFrame { public: - // Normally you will create this class by calling BrowserFrame::Create. - // Init must be called before using this class, which Create will do for you. - BrowserFrameWin(BrowserView* browser_view, Profile* profile); + BrowserFrameWin(BrowserFrame* browser_frame, BrowserView* browser_view); virtual ~BrowserFrameWin(); BrowserView* browser_view() const { return browser_view_; } @@ -40,41 +36,29 @@ class BrowserFrameWin : public BrowserFrame, // Overridden from views::WindowWin: virtual int GetShowState() const OVERRIDE; virtual gfx::Insets GetClientAreaInsets() const OVERRIDE; - virtual bool GetAccelerator(int cmd_id, - ui::Accelerator* accelerator) OVERRIDE; + virtual void UpdateFrameAfterFrameChange() OVERRIDE; virtual void OnEndSession(BOOL ending, UINT logoff) OVERRIDE; virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu) OVERRIDE; virtual void OnWindowPosChanged(WINDOWPOS* window_pos) OVERRIDE; - virtual ui::ThemeProvider* GetThemeProvider() const OVERRIDE; virtual void OnScreenReaderDetected() OVERRIDE; - // Overridden from views::Window: - virtual void Activate() OVERRIDE; - virtual bool IsAppWindow() const OVERRIDE { return true; } - virtual void UpdateFrameAfterFrameChange() OVERRIDE; - virtual views::RootView* CreateRootView() OVERRIDE; - virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; - // Overridden from NativeBrowserFrame: virtual views::NativeWindow* AsNativeWindow() OVERRIDE; virtual const views::NativeWindow* AsNativeWindow() const OVERRIDE; - virtual BrowserNonClientFrameView* CreateBrowserNonClientFrameView() OVERRIDE; virtual int GetMinimizeButtonOffset() const OVERRIDE; - virtual ui::ThemeProvider* GetThemeProviderForFrame() const OVERRIDE; - virtual bool AlwaysUseNativeFrame() const OVERRIDE; virtual void TabStripDisplayModeChanged() OVERRIDE; private: // Updates the DWM with the frame bounds. void UpdateDWMFrame(); - NativeBrowserFrameDelegate* delegate_; - // The BrowserView is our ClientView. This is a pointer to it. BrowserView* browser_view_; + BrowserFrame* browser_frame_; + DISALLOW_COPY_AND_ASSIGN(BrowserFrameWin); }; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index bc4b9fc..1f6dee6 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -292,7 +292,7 @@ class ResizeCorner : public views::View { // currently in a window. views::Window* GetWindow() { views::Widget* widget = GetWidget(); - return widget ? widget->GetWindow() : NULL; + return widget ? widget->GetContainingWindow() : NULL; } DISALLOW_COPY_AND_ASSIGN(ResizeCorner); @@ -579,8 +579,8 @@ void BrowserView::Show() { BrowserList::SetLastActive(browser()); // If the window is already visible, just activate it. - if (frame_->GetWindow()->IsVisible()) { - frame_->GetWindow()->Activate(); + if (frame_->IsVisible()) { + frame_->Activate(); return; } @@ -596,13 +596,12 @@ void BrowserView::Show() { // that should be added and this should be removed. RestoreFocus(); - frame_->GetWindow()->Show(); + frame_->Show(); } void BrowserView::ShowInactive() { - views::Window* window = frame_->GetWindow(); - if (!window->IsVisible()) - window->ShowInactive(); + if (!frame_->IsVisible()) + frame_->ShowInactive(); } void BrowserView::SetBounds(const gfx::Rect& bounds) { @@ -613,26 +612,26 @@ void BrowserView::SetBounds(const gfx::Rect& bounds) { void BrowserView::Close() { BrowserBubbleHost::Close(); - frame_->GetWindow()->CloseWindow(); + frame_->Close(); } void BrowserView::Activate() { - frame_->GetWindow()->Activate(); + frame_->Activate(); } void BrowserView::Deactivate() { - frame_->GetWindow()->Deactivate(); + frame_->Deactivate(); } bool BrowserView::IsActive() const { - return frame_->GetWindow()->IsActive(); + return frame_->IsActive(); } void BrowserView::FlashFrame() { #if defined(OS_WIN) FLASHWINFO fwi; fwi.cbSize = sizeof(fwi); - fwi.hwnd = frame_->GetWindow()->GetNativeWindow(); + fwi.hwnd = frame_->GetNativeWindow(); fwi.dwFlags = FLASHW_ALL; fwi.uCount = 4; fwi.dwTimeout = 0; @@ -643,7 +642,7 @@ void BrowserView::FlashFrame() { } gfx::NativeWindow BrowserView::GetNativeHandle() { - return GetWidget()->GetWindow()->GetNativeWindow(); + return GetWidget()->GetContainingWindow()->GetNativeWindow(); } BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() { @@ -708,9 +707,9 @@ void BrowserView::ToolbarSizeChanged(bool is_animating) { } void BrowserView::UpdateTitleBar() { - frame_->GetWindow()->UpdateWindowTitle(); + frame_->UpdateWindowTitle(); if (ShouldShowWindowIcon() && !loading_animation_timer_.IsRunning()) - frame_->GetWindow()->UpdateWindowIcon(); + frame_->UpdateWindowIcon(); } void BrowserView::ShelfVisibilityChanged() { @@ -746,15 +745,15 @@ void BrowserView::SetStarredState(bool is_starred) { } gfx::Rect BrowserView::GetRestoredBounds() const { - return frame_->GetWindow()->GetNormalBounds(); + return frame_->GetNormalBounds(); } gfx::Rect BrowserView::GetBounds() const { - return frame_->GetWindow()->GetBounds(); + return frame_->GetBounds(); } bool BrowserView::IsMaximized() const { - return frame_->GetWindow()->IsMaximized(); + return frame_->IsMaximized(); } void BrowserView::SetFullscreen(bool fullscreen) { @@ -766,12 +765,12 @@ void BrowserView::SetFullscreen(bool fullscreen) { #else // On Linux changing fullscreen is async. Ask the window to change it's // fullscreen state, and when done invoke ProcessFullscreen. - frame_->GetWindow()->SetFullscreen(fullscreen); + frame_->SetFullscreen(fullscreen); #endif } bool BrowserView::IsFullscreen() const { - return frame_->GetWindow()->IsFullscreen(); + return frame_->IsFullscreen(); } bool BrowserView::IsFullscreenBubbleVisible() const { @@ -979,7 +978,7 @@ bool BrowserView::IsToolbarVisible() const { void BrowserView::DisableInactiveFrame() { #if defined(OS_WIN) - frame_->GetWindow()->DisableInactiveRendering(); + frame_->DisableInactiveRendering(); #endif // No tricks are needed to get the right behavior on Linux. } @@ -1113,7 +1112,7 @@ void BrowserView::ShowCreateChromeAppShortcutsDialog(Profile* profile, } void BrowserView::UserChangedTheme() { - frame_->GetWindow()->FrameTypeChanged(); + frame_->FrameTypeChanged(); } int BrowserView::GetExtraRenderViewHeight() const { @@ -1598,7 +1597,7 @@ bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { bounds->height() + toolbar_->GetPreferredSize().height()); } - gfx::Rect window_rect = frame_->GetWindow()->non_client_view()-> + gfx::Rect window_rect = frame_->non_client_view()-> GetWindowBoundsForClientBounds(*bounds); window_rect.set_origin(bounds->origin()); @@ -1680,7 +1679,7 @@ bool BrowserView::CanClose() { // Tab strip isn't empty. Hide the frame (so it appears to have closed // immediately) and close all the tabs, allowing the renderers to shut // down. When the tab strip is empty we'll be called back again. - frame_->GetWindow()->HideWindow(); + frame_->HideWindow(); browser_->OnWindowClosing(); return false; } @@ -1688,7 +1687,7 @@ bool BrowserView::CanClose() { // Empty TabStripModel, it's now safe to allow the Window to be closed. NotificationService::current()->Notify( NotificationType::WINDOW_CLOSED, - Source<gfx::NativeWindow>(frame_->GetWindow()->GetNativeWindow()), + Source<gfx::NativeWindow>(frame_->GetNativeWindow()), NotificationService::NoDetails()); return true; } @@ -1698,10 +1697,9 @@ int BrowserView::NonClientHitTest(const gfx::Point& point) { // The following code is not in the LayoutManager because it's // independent of layout and also depends on the ResizeCorner which // is private. - if (!frame_->GetWindow()->IsMaximized() && - !frame_->GetWindow()->IsFullscreen()) { + if (!frame_->IsMaximized() && !frame_->IsFullscreen()) { CRect client_rect; - ::GetClientRect(frame_->GetWindow()->GetNativeWindow(), &client_rect); + ::GetClientRect(frame_->GetNativeWindow(), &client_rect); gfx::Size resize_corner_size = ResizeCorner::GetSize(); gfx::Rect resize_corner_rect(client_rect.right - resize_corner_size.width(), client_rect.bottom - resize_corner_size.height(), @@ -1803,8 +1801,7 @@ void BrowserView::GetAccessibleState(ui::AccessibleViewState* state) { SkColor BrowserView::GetInfoBarSeparatorColor() const { // NOTE: Keep this in sync with ToolbarView::OnPaint()! - return (IsTabStripVisible() || - !frame_->GetWindow()->non_client_view()->UseNativeFrame()) ? + return (IsTabStripVisible() || !frame_->non_client_view()->UseNativeFrame()) ? ResourceBundle::toolbar_separator_color : SK_ColorBLACK; } @@ -1934,7 +1931,7 @@ void BrowserView::Init() { if (AeroPeekManager::Enabled()) { aeropeek_manager_.reset(new AeroPeekManager( - frame_->GetWindow()->GetNativeWindow())); + frame_->GetNativeWindow())); browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); } #endif @@ -2002,7 +1999,7 @@ void BrowserView::InitSystemMenu() { BuildSystemMenuForAppOrPopupWindow(); system_menu_.reset( new views::NativeMenuWin(system_menu_contents_.get(), - frame_->GetWindow()->GetNativeWindow())); + frame_->GetNativeWindow())); system_menu_->Rebuild(); } #endif @@ -2254,8 +2251,7 @@ void BrowserView::ProcessFullscreen(bool fullscreen) { #endif } #if defined(OS_WIN) - static_cast<views::WindowWin*>( - frame_->GetWindow()->native_window())->PushForceHidden(); + static_cast<views::WindowWin*>(frame_->native_window())->PushForceHidden(); #endif // Notify bookmark bar, so it can set itself to the appropriate drawing state. @@ -2264,7 +2260,7 @@ void BrowserView::ProcessFullscreen(bool fullscreen) { // Toggle fullscreen mode. #if defined(OS_WIN) - frame_->GetWindow()->SetFullscreen(fullscreen); + frame_->SetFullscreen(fullscreen); #endif // No need to invoke SetFullscreen for linux as this code is executed // once we're already fullscreen on linux. @@ -2296,8 +2292,7 @@ void BrowserView::ProcessFullscreen(bool fullscreen) { ignore_layout_ = false; Layout(); #if defined(OS_WIN) - static_cast<views::WindowWin*>( - frame_->GetWindow()->native_window())->PopForceHidden(); + static_cast<views::WindowWin*>(frame_->native_window())->PopForceHidden(); #endif } @@ -2580,11 +2575,9 @@ BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { // Create the view and the frame. The frame will attach itself via the view // so we don't need to do anything with the pointer. BrowserView* view = new BrowserView(browser); - BrowserFrame::Create(view, browser->profile()); - + (new BrowserFrame(view))->InitBrowserFrame(); view->GetWindow()->non_client_view()->SetAccessibleName( l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); - return view; } #endif diff --git a/chrome/browser/ui/views/frame/browser_view_layout.cc b/chrome/browser/ui/views/frame/browser_view_layout.cc index ebd0403..16ebf34 100644 --- a/chrome/browser/ui/views/frame/browser_view_layout.cc +++ b/chrome/browser/ui/views/frame/browser_view_layout.cc @@ -556,8 +556,8 @@ void BrowserViewLayout::LayoutTabContents(int top, int bottom) { // TODO(alekseys): layout sidebar minitabs and adjust reserved rect // accordingly. gfx::Rect browser_reserved_rect; - if (!browser_view_->frame_->GetWindow()->IsMaximized() && - !browser_view_->frame_->GetWindow()->IsFullscreen()) { + if (!browser_view_->frame_->IsMaximized() && + !browser_view_->frame_->IsFullscreen()) { gfx::Size resize_corner_size = browser_view_->GetResizeCornerSize(); if (!resize_corner_size.IsEmpty()) { gfx::Rect bounds = browser_view_->GetContentsBounds(); diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc index b3b96ef..2f5bd45 100644 --- a/chrome/browser/ui/views/frame/contents_container.cc +++ b/chrome/browser/ui/views/frame/contents_container.cc @@ -152,8 +152,6 @@ void ContentsContainer::Layout() { void ContentsContainer::CreateOverlay(int initial_opacity) { DCHECK(!active_overlay_); - active_overlay_ = views::Widget::CreateWidget(); - active_overlay_->SetOpacity(initial_opacity); gfx::Point screen_origin; views::View::ConvertPointToScreen(active_, &screen_origin); gfx::Rect overlay_bounds(screen_origin, active_->size()); @@ -162,11 +160,13 @@ void ContentsContainer::CreateOverlay(int initial_opacity) { params.accept_events = false; params.parent = active_->GetWidget()->GetNativeView(); params.bounds = overlay_bounds; + active_overlay_ = new views::Widget; active_overlay_->Init(params); overlay_view_ = new OverlayContentView(this); overlay_view_->set_background( views::Background::CreateSolidBackground(SK_ColorWHITE)); active_overlay_->SetContentsView(overlay_view_); + active_overlay_->SetOpacity(initial_opacity); active_overlay_->Show(); active_overlay_->MoveAboveWidget(active_->GetWidget()); } diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc index f3daf8f..11e2950 100644 --- a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc +++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc @@ -130,8 +130,7 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( // a tab strip until the left end of this window without considering the size // of window controls in RTL languages. if (base::i18n::IsRTL()) { - if (!browser_view_->ShouldShowOffTheRecordAvatar() && - frame_->GetWindow()->IsMaximized()) + if (!browser_view_->ShouldShowOffTheRecordAvatar() && frame_->IsMaximized()) tabstrip_x += otr_avatar_bounds_.x(); minimize_button_offset = width(); } @@ -141,7 +140,7 @@ gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( profile_button_->GetPreferredSize().width() + ProfileMenuButton::kProfileTagHorizontalSpacing : 0); int tabstrip_width = minimize_button_offset - tabstrip_x - - (frame_->GetWindow()->IsMaximized() ? + (frame_->IsMaximized() ? maximized_spacing : kNewTabCaptionRestoredSpacing); return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), std::max(0, tabstrip_width), @@ -178,7 +177,7 @@ bool GlassBrowserFrameView::AlwaysUseNativeFrame() const { gfx::Rect GlassBrowserFrameView::GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const { - HWND hwnd = frame_->GetWindow()->GetNativeWindow(); + HWND hwnd = frame_->GetNativeWindow(); if (!browser_view_->IsTabStripVisible() && hwnd) { // If we don't have a tabstrip, we're either a popup or an app window, in // which case we have a standard size non-client area and can just use @@ -206,8 +205,7 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point)) return HTNOWHERE; - int frame_component = - frame_->GetWindow()->client_view()->NonClientHitTest(point); + int frame_component = frame_->client_view()->NonClientHitTest(point); // See if we're in the sysmenu region. We still have to check the tabstrip // first so that clicks in a tab don't get treated as sysmenu clicks. @@ -229,7 +227,7 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, frame_border_thickness, nonclient_border_thickness, frame_border_thickness, kResizeAreaCornerSize - frame_border_thickness, - frame_->GetWindow()->window_delegate()->CanResize()); + frame_->window_delegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -254,7 +252,7 @@ void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { PaintToolbarBackground(canvas); if (browser_view_->ShouldShowOffTheRecordAvatar()) PaintOTRAvatar(canvas); - if (!frame_->GetWindow()->IsMaximized()) + if (!frame_->IsMaximized()) PaintRestoredClientEdge(canvas); } @@ -267,12 +265,12 @@ void GlassBrowserFrameView::Layout() { bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const { // The ProfileMenuButton intrudes into the client area when the window is // maximized. - if (frame_->GetWindow()->IsMaximized() && show_profile_button() && + if (frame_->IsMaximized() && show_profile_button() && profile_button_->IsVisible() && profile_button_->GetMirroredBounds().Contains(l)) { return true; } else { - return !GetWindow()->client_view()->bounds().Contains(l); + return !frame_->client_view()->bounds().Contains(l); } } @@ -280,14 +278,12 @@ bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const { // GlassBrowserFrameView, private: int GlassBrowserFrameView::FrameBorderThickness() const { - views::Window* window = frame_->GetWindow(); - return (window->IsMaximized() || window->IsFullscreen()) ? + return (frame_->IsMaximized() || frame_->IsFullscreen()) ? 0 : GetSystemMetrics(SM_CXSIZEFRAME); } int GlassBrowserFrameView::NonClientBorderThickness() const { - views::Window* window = frame_->GetWindow(); - if (window->IsMaximized() || window->IsFullscreen()) + if (frame_->IsMaximized() || frame_->IsFullscreen()) return 0; return browser_view_->UseVerticalTabs() ? @@ -298,7 +294,7 @@ int GlassBrowserFrameView::NonClientBorderThickness() const { int GlassBrowserFrameView::NonClientTopBorderHeight( bool restored, bool ignore_vertical_tabs) const { - if (!restored && frame_->GetWindow()->IsFullscreen()) + if (!restored && frame_->IsFullscreen()) return 0; // We'd like to use FrameBorderThickness() here, but the maximized Aero glass // frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border @@ -436,7 +432,7 @@ void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { // of how tall the toolbar itself is. int client_area_top = browser_view_->UseVerticalTabs() ? client_area_bounds.y() : - (frame_->GetWindow()->client_view()->y() + + (frame_->client_view()->y() + browser_view_->GetToolbarBounds().y() + tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height()); int client_area_bottom = @@ -497,7 +493,7 @@ void GlassBrowserFrameView::LayoutOTRAvatar() { browser_view_->GetTabStripHeight() - kOTRBottomSpacing; otr_restored_y = otr_bottom - otr_avatar_icon.height(); } - int otr_y = frame_->GetWindow()->IsMaximized() ? + int otr_y = frame_->IsMaximized() ? (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : otr_restored_y; otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_avatar_icon.width(), @@ -536,7 +532,7 @@ void GlassBrowserFrameView::LayoutProfileTag() { ProfileMenuButton::kProfileTagHorizontalSpacing - // - the width of the profile button profile_button_->GetPreferredSize().width(); - int y_maximized_offset = frame_->GetWindow()->IsMaximized() ? + int y_maximized_offset = frame_->IsMaximized() ? kProfileElementMaximizedYOffset : 0; profile_button_->SetBounds( x_tag, @@ -570,7 +566,7 @@ void GlassBrowserFrameView::StartThrobber() { throbber_running_ = true; throbber_frame_ = 0; InitThrobberIcons(); - SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON, + SendMessage(frame_->GetNativeWindow(), WM_SETICON, static_cast<WPARAM>(ICON_SMALL), reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); } @@ -592,13 +588,13 @@ void GlassBrowserFrameView::StopThrobber() { // Fallback to class icon. if (!frame_icon) { frame_icon = reinterpret_cast<HICON>(GetClassLongPtr( - frame_->GetWindow()->GetNativeWindow(), GCLP_HICONSM)); + frame_->GetNativeWindow(), GCLP_HICONSM)); } // This will reset the small icon which we set in the throbber code. // WM_SETICON with NULL icon restores the icon for title bar but not // for taskbar. See http://crbug.com/29996 - SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON, + SendMessage(frame_->GetNativeWindow(), WM_SETICON, static_cast<WPARAM>(ICON_SMALL), reinterpret_cast<LPARAM>(frame_icon)); } @@ -606,7 +602,7 @@ void GlassBrowserFrameView::StopThrobber() { void GlassBrowserFrameView::DisplayNextThrobberFrame() { throbber_frame_ = (throbber_frame_ + 1) % kThrobberIconCount; - SendMessage(frame_->GetWindow()->GetNativeWindow(), WM_SETICON, + SendMessage(frame_->GetNativeWindow(), WM_SETICON, static_cast<WPARAM>(ICON_SMALL), reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); } diff --git a/chrome/browser/ui/views/frame/native_browser_frame.h b/chrome/browser/ui/views/frame/native_browser_frame.h index f72ec29..120fa1f 100644 --- a/chrome/browser/ui/views/frame/native_browser_frame.h +++ b/chrome/browser/ui/views/frame/native_browser_frame.h @@ -6,38 +6,27 @@ #define CHROME_BROWSER_UI_VIEWS_FRAME_NATIVE_BROWSER_FRAME_H_ #pragma once -class BrowserNonClientFrameView; - -namespace gfx { -class Rect; -} - -namespace ui { -class ThemeProvider; -} - -namespace views { -class NativeWindow; -class View; -} +class BrowserView; class NativeBrowserFrame { public: virtual ~NativeBrowserFrame() {} + // Construct a platform-specific implementation of this interface. + static NativeBrowserFrame* CreateNativeBrowserFrame( + BrowserFrame* browser_frame, + BrowserView* browser_view); + virtual views::NativeWindow* AsNativeWindow() = 0; virtual const views::NativeWindow* AsNativeWindow() const = 0; protected: friend class BrowserFrame; - virtual BrowserNonClientFrameView* CreateBrowserNonClientFrameView() = 0; - // BrowserFrame pass-thrus --------------------------------------------------- // See browser_frame.h for documentation: virtual int GetMinimizeButtonOffset() const = 0; - virtual ui::ThemeProvider* GetThemeProviderForFrame() const = 0; - virtual bool AlwaysUseNativeFrame() const = 0; + // TODO(beng): replace with some kind of "framechanged" signal to Window. virtual void TabStripDisplayModeChanged() = 0; }; diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc index da4ca70..7efd98b 100644 --- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc @@ -138,7 +138,7 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, window_icon_(NULL), frame_(frame), browser_view_(browser_view) { - ui::ThemeProvider* tp = frame_->GetThemeProviderForFrame(); + ui::ThemeProvider* tp = frame_->GetThemeProvider(); SkColor color = tp->GetColor(ThemeService::COLOR_BUTTON_BACKGROUND); SkBitmap* background = tp->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND); @@ -243,8 +243,7 @@ gfx::Rect OpaqueBrowserFrameView::GetBoundsForReservedArea() const { int OpaqueBrowserFrameView::NonClientTopBorderHeight( bool restored, bool ignore_vertical_tabs) const { - views::Window* window = frame_->GetWindow(); - views::WindowDelegate* delegate = window->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); // |delegate| may be NULL if called from callback of InputMethodChanged while // a window is being destroyed. // See more discussion at http://crosbug.com/8958 @@ -258,7 +257,7 @@ int OpaqueBrowserFrameView::NonClientTopBorderHeight( return FrameBorderThickness(restored) - ((browser_view_->IsTabStripVisible() && !restored && - window->IsMaximized()) ? kTabstripTopShadowThickness : 0); + frame_->IsMaximized()) ? kTabstripTopShadowThickness : 0); } /////////////////////////////////////////////////////////////////////////////// @@ -287,7 +286,7 @@ gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( profile_button_->GetPreferredSize().width() + ProfileMenuButton::kProfileTagHorizontalSpacing : 0); int tabstrip_width = minimize_button_->x() - tabstrip_x - - (frame_->GetWindow()->IsMaximized() ? + (frame_->IsMaximized() ? maximized_spacing : kNewTabCaptionRestoredSpacing); int tabstrip_height = 0; if (tabstrip) @@ -299,8 +298,8 @@ gfx::Rect OpaqueBrowserFrameView::GetBoundsForTabStrip( int OpaqueBrowserFrameView::GetHorizontalTabStripVerticalOffset( bool restored) const { return NonClientTopBorderHeight(restored, true) + ((!restored && - (frame_->GetWindow()->IsMaximized() || - frame_->GetWindow()->IsFullscreen())) ? + (frame_->IsMaximized() || + frame_->IsFullscreen())) ? 0 : kNonClientRestoredExtraThickness); } @@ -315,7 +314,7 @@ gfx::Size OpaqueBrowserFrameView::GetMinimumSize() { min_size.Enlarge(2 * border_thickness, NonClientTopBorderHeight(false, false) + border_thickness); - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); int min_titlebar_width = (2 * FrameBorderThickness(false)) + kIconLeftSpacing + (delegate && delegate->ShouldShowWindowIcon() ? @@ -360,14 +359,14 @@ int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { return HTNOWHERE; int frame_component = - frame_->GetWindow()->client_view()->NonClientHitTest(point); + frame_->client_view()->NonClientHitTest(point); // See if we're in the sysmenu region. We still have to check the tabstrip // first so that clicks in a tab don't get treated as sysmenu clicks. gfx::Rect sysmenu_rect(IconBounds()); // In maximized mode we extend the rect to the screen corner to take advantage // of Fitts' Law. - if (frame_->GetWindow()->IsMaximized()) + if (frame_->IsMaximized()) sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); if (sysmenu_rect.Contains(point)) @@ -395,7 +394,7 @@ int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { profile_button_->GetMirroredBounds().Contains(point)) return HTCLIENT; - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); if (!delegate) { LOG(WARNING) << "delegate is NULL, returning safe default."; return HTCAPTION; @@ -411,7 +410,7 @@ void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) { DCHECK(window_mask); - if (frame_->GetWindow()->IsMaximized() || frame_->GetWindow()->IsFullscreen()) + if (frame_->IsMaximized() || frame_->IsFullscreen()) return; views::GetDefaultWindowMask(size, window_mask); @@ -447,11 +446,10 @@ void OpaqueBrowserFrameView::RunMenu(views::View* source, // OpaqueBrowserFrameView, views::View overrides: void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { - views::Window* window = frame_->GetWindow(); - if (window->IsFullscreen()) + if (frame_->IsFullscreen()) return; // Nothing is visible, so don't bother to paint. - if (window->IsMaximized()) + if (frame_->IsMaximized()) PaintMaximizedFrameBorder(canvas); else PaintRestoredFrameBorder(canvas); @@ -461,7 +459,7 @@ void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { PaintToolbarBackground(canvas); if (browser_view_->ShouldShowOffTheRecordAvatar()) PaintOTRAvatar(canvas); - if (!window->IsMaximized()) + if (!frame_->IsMaximized()) PaintRestoredClientEdge(canvas); } @@ -483,8 +481,7 @@ bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { bool vertical_tabs = browser_view_->UseVerticalTabs(); gfx::Rect tabstrip_bounds = GetBoundsForTabStrip(browser_view_->tabstrip()); gfx::Point tabstrip_origin(tabstrip_bounds.origin()); - View::ConvertPointToView(frame_->GetWindow()->client_view(), - this, &tabstrip_origin); + View::ConvertPointToView(frame_->client_view(), this, &tabstrip_origin); tabstrip_bounds.set_origin(tabstrip_origin); if ((!vertical_tabs && l.y() > tabstrip_bounds.bottom()) || (vertical_tabs && l.x() > tabstrip_bounds.right())) { @@ -494,13 +491,13 @@ bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { // Claim it only if we're also not in the compact navigation buttons. if (browser_view_->UseCompactNavigationBar()) { if (ConvertedContainsCheck(browser_view_->GetCompactNavigationBarBounds(), - frame_->GetWindow()->client_view(), + frame_->client_view(), static_cast<const View*>(this), l)) { return false; } if (ConvertedContainsCheck(browser_view_->GetCompactOptionsBarBounds(), - frame_->GetWindow()->client_view(), + frame_->client_view(), static_cast<const View*>(this), l)) { return false; @@ -525,15 +522,14 @@ void OpaqueBrowserFrameView::GetAccessibleState( void OpaqueBrowserFrameView::ButtonPressed(views::Button* sender, const views::Event& event) { - views::Window* window = frame_->GetWindow(); if (sender == minimize_button_) - window->Minimize(); + frame_->Minimize(); else if (sender == maximize_button_) - window->Maximize(); + frame_->Maximize(); else if (sender == restore_button_) - window->Restore(); + frame_->Restore(); else if (sender == close_button_) - window->CloseWindow(); + frame_->Close(); } /////////////////////////////////////////////////////////////////////////////// @@ -548,7 +544,7 @@ bool OpaqueBrowserFrameView::ShouldTabIconViewAnimate() const { } SkBitmap OpaqueBrowserFrameView::GetFaviconForTabIconView() { - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); if (!delegate) { LOG(WARNING) << "delegate is NULL, returning safe default."; return SkBitmap(); @@ -572,8 +568,7 @@ void OpaqueBrowserFrameView::Observe(NotificationType type, // OpaqueBrowserFrameView, private: int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { - views::Window* window = frame_->GetWindow(); - return (!restored && (window->IsMaximized() || window->IsFullscreen())) ? + return (!restored && (frame_->IsMaximized() || frame_->IsFullscreen())) ? 0 : kFrameBorderThickness; } @@ -583,9 +578,8 @@ int OpaqueBrowserFrameView::TopResizeHeight() const { int OpaqueBrowserFrameView::NonClientBorderThickness() const { // When we fill the screen, we don't show a client edge. - views::Window* window = frame_->GetWindow(); return FrameBorderThickness(false) + - ((window->IsMaximized() || window->IsFullscreen()) ? + ((frame_->IsMaximized() || frame_->IsFullscreen()) ? 0 : kClientEdgeThickness); } @@ -596,14 +590,13 @@ void OpaqueBrowserFrameView::ModifyMaximizedFramePainting( int OpaqueBrowserFrameView::CaptionButtonY(bool restored) const { // Maximized buttons start at window top so that even if their images aren't // drawn flush with the screen edge, they still obey Fitts' Law. - return (!restored && frame_->GetWindow()->IsMaximized()) ? + return (!restored && frame_->IsMaximized()) ? FrameBorderThickness(false) : kFrameShadowThickness; } int OpaqueBrowserFrameView::TitlebarBottomThickness(bool restored) const { return kTitlebarTopAndBottomEdgeThickness + - ((!restored && frame_->GetWindow()->IsMaximized()) ? - 0 : kClientEdgeThickness); + ((!restored && frame_->IsMaximized()) ? 0 : kClientEdgeThickness); } int OpaqueBrowserFrameView::IconSize() const { @@ -620,7 +613,7 @@ gfx::Rect OpaqueBrowserFrameView::IconBounds() const { int size = IconSize(); int frame_thickness = FrameBorderThickness(false); int y; - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); if (delegate && (delegate->ShouldShowWindowIcon() || delegate->ShouldShowWindowTitle())) { // Our frame border has a different "3D look" than Windows'. Theirs has a @@ -631,7 +624,7 @@ gfx::Rect OpaqueBrowserFrameView::IconBounds() const { // with restored windows, so when the window is restored, instead of // calculating the remaining space from below the frame border, we calculate // from below the 3D edge. - int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ? + int unavailable_px_at_top = frame_->IsMaximized() ? frame_thickness : kTitlebarTopAndBottomEdgeThickness; // When the icon is shorter than the minimum space we reserve for the // caption button, we vertically center it. We want to bias rounding to put @@ -768,8 +761,6 @@ void OpaqueBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { ui::ThemeProvider* tp = GetThemeProvider(); - views::Window* window = frame_->GetWindow(); - // Window frame mode and color SkBitmap* theme_frame; @@ -828,13 +819,13 @@ void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { tp->GetBitmapNamed(IDR_APP_TOP_CENTER); int edge_height = top_center->height() - kClientEdgeThickness; canvas->TileImageInt(*top_center, 0, - window->client_view()->y() - edge_height, width(), edge_height); + frame_->client_view()->y() - edge_height, width(), edge_height); } } void OpaqueBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) { // The window icon is painted by the TabIconView. - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); if (!delegate) { LOG(WARNING) << "delegate is NULL"; return; @@ -986,7 +977,7 @@ void OpaqueBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) { void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { ui::ThemeProvider* tp = GetThemeProvider(); - int client_area_top = frame_->GetWindow()->client_view()->y(); + int client_area_top = frame_->client_view()->y(); int image_top = client_area_top; gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); @@ -1072,7 +1063,7 @@ void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { } void OpaqueBrowserFrameView::LayoutWindowControls() { - bool is_maximized = frame_->GetWindow()->IsMaximized(); + bool is_maximized = frame_->IsMaximized(); close_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, views::ImageButton::ALIGN_BOTTOM); int caption_y = CaptionButtonY(false); @@ -1095,7 +1086,7 @@ void OpaqueBrowserFrameView::LayoutWindowControls() { // as maximized mode. // TODO(oshima): Optimize the relayout logic to defer the frame view's // relayout until it is necessary, i.e when it becomes visible. - if (is_maximized || frame_->GetWindow()->IsFullscreen()) { + if (is_maximized || frame_->IsFullscreen()) { minimize_button_->SetVisible(false); restore_button_->SetVisible(false); maximize_button_->SetVisible(false); @@ -1121,7 +1112,7 @@ void OpaqueBrowserFrameView::LayoutWindowControls() { // When the window is restored, we show a maximized button; otherwise, we show // a restore button. - bool is_restored = !is_maximized && !frame_->GetWindow()->IsMinimized(); + bool is_restored = !is_maximized && !frame_->IsMinimized(); views::ImageButton* invisible_button = is_restored ? restore_button_ : maximize_button_; invisible_button->SetVisible(false); @@ -1150,7 +1141,7 @@ void OpaqueBrowserFrameView::LayoutTitleBar() { // The window title is based on the calculated icon position, even when there // is no icon. gfx::Rect icon_bounds(IconBounds()); - views::WindowDelegate* delegate = frame_->GetWindow()->window_delegate(); + views::WindowDelegate* delegate = frame_->window_delegate(); if (delegate && delegate->ShouldShowWindowIcon()) window_icon_->SetBoundsRect(icon_bounds); @@ -1182,7 +1173,7 @@ void OpaqueBrowserFrameView::LayoutOTRAvatar() { browser_view_->GetTabStripHeight() - kOTRBottomSpacing; otr_restored_y = otr_bottom - otr_avatar_icon.height(); } - int otr_y = frame_->GetWindow()->IsMaximized() ? + int otr_y = frame_->IsMaximized() ? (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : otr_restored_y; otr_avatar_bounds_.SetRect(NonClientBorderThickness() + kOTRSideSpacing, @@ -1215,7 +1206,7 @@ void OpaqueBrowserFrameView::LayoutProfileTag() { profile_button_->GetPreferredSize().width(); // Adjust for different default font sizes on different Windows platforms. int y_tag = profile_button_->font().GetHeight() < 14 ? 2 : 0; - int y_maximized_offset = frame_->GetWindow()->IsMaximized() ? + int y_maximized_offset = frame_->IsMaximized() ? kProfileElementMaximizedYOffset : 0; profile_button_->SetBounds( x_tag, diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble.cc b/chrome/browser/ui/views/fullscreen_exit_bubble.cc index d72552d..1c18697 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble.cc @@ -132,8 +132,7 @@ FullscreenExitBubble::FullscreenExitBubble( this, UTF16ToWideHack(accelerator.GetShortcutText())); // Initialize the popup. - popup_ = views::Widget::CreateWidget(); - popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); + popup_ = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.can_activate = false; @@ -142,6 +141,7 @@ FullscreenExitBubble::FullscreenExitBubble( params.bounds = GetPopupRect(false); popup_->Init(params); popup_->SetContentsView(view_); + popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); popup_->Show(); // This does not activate the popup. // Start the initial delay timer and begin watching the mouse. diff --git a/chrome/browser/ui/views/generic_info_view_unittest.cc b/chrome/browser/ui/views/generic_info_view_unittest.cc index d38512f..5fe6dc2 100644 --- a/chrome/browser/ui/views/generic_info_view_unittest.cc +++ b/chrome/browser/ui/views/generic_info_view_unittest.cc @@ -29,7 +29,7 @@ TEST_F(GenericInfoViewTest, GenericInfoView) { const string16 kName = ASCIIToUTF16("Name"); const string16 kValue = ASCIIToUTF16("Value"); - views::Widget* widget = views::Widget::CreateWidget(); + views::Widget* widget = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.bounds = gfx::Rect(0, 0, 100, 100); widget->Init(params); diff --git a/chrome/browser/ui/views/handle_web_keyboard_event_gtk.cc b/chrome/browser/ui/views/handle_web_keyboard_event_gtk.cc index 4ae9a79..d6ec1fc1 100644 --- a/chrome/browser/ui/views/handle_web_keyboard_event_gtk.cc +++ b/chrome/browser/ui/views/handle_web_keyboard_event_gtk.cc @@ -11,6 +11,7 @@ void HandleWebKeyboardEvent(views::Widget* widget, const NativeWebKeyboardEvent& event) { if (widget && event.os_event && !event.skip_in_browser) { views::KeyEvent views_event(reinterpret_cast<GdkEvent*>(event.os_event)); - static_cast<views::WidgetGtk*>(widget)->HandleKeyboardEvent(views_event); + static_cast<views::WidgetGtk*>(widget->native_widget())-> + HandleKeyboardEvent(views_event); } } diff --git a/chrome/browser/ui/views/html_dialog_view.cc b/chrome/browser/ui/views/html_dialog_view.cc index 010b943..55f4148 100644 --- a/chrome/browser/ui/views/html_dialog_view.cc +++ b/chrome/browser/ui/views/html_dialog_view.cc @@ -148,7 +148,7 @@ void HtmlDialogView::OnDialogClosed(const std::string& json_retval) { delegate_ = NULL; // We will not communicate further with the delegate. dialog_delegate->OnDialogClosed(json_retval); } - window()->CloseWindow(); + window()->Close(); } void HtmlDialogView::OnWindowClosed() { @@ -193,7 +193,8 @@ void HtmlDialogView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { DefWindowProc(event.os_event.hwnd, event.os_event.message, event.os_event.wParam, event.os_event.lParam); #elif defined(TOOLKIT_USES_GTK) - views::WindowGtk* window_gtk = static_cast<views::WindowGtk*>(window()); + views::WindowGtk* window_gtk = + static_cast<views::WindowGtk*>(window()->native_window()); if (event.os_event && !event.skip_in_browser) { views::KeyEvent views_event(reinterpret_cast<GdkEvent*>(event.os_event)); window_gtk->HandleKeyboardEvent(views_event); diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index 2db7e15..c913ca2 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -263,7 +263,7 @@ void HungRendererDialogView::EndForTabContents(TabContents* contents) { DCHECK(contents); if (contents_ && contents_->GetRenderProcessHost() == contents->GetRenderProcessHost()) { - window()->CloseWindow(); + window()->Close(); // Since we're closing, we no longer need this TabContents. contents_ = NULL; } diff --git a/chrome/browser/ui/views/importer/import_progress_dialog_view.cc b/chrome/browser/ui/views/importer/import_progress_dialog_view.cc index f82f6b6..624dda5 100644 --- a/chrome/browser/ui/views/importer/import_progress_dialog_view.cc +++ b/chrome/browser/ui/views/importer/import_progress_dialog_view.cc @@ -275,7 +275,7 @@ void ImportProgressDialogView::ImportEnded() { // In every case, we need to close the UI now. importing_ = false; importer_host_->SetObserver(NULL); - window()->CloseWindow(); + window()->Close(); if (importer_observer_) importer_observer_->ImportCompleted(); } diff --git a/chrome/browser/ui/views/js_modal_dialog_views.cc b/chrome/browser/ui/views/js_modal_dialog_views.cc index 12d0664..6bccb5d 100644 --- a/chrome/browser/ui/views/js_modal_dialog_views.cc +++ b/chrome/browser/ui/views/js_modal_dialog_views.cc @@ -54,7 +54,7 @@ void JSModalDialogViews::ActivateAppModalDialog() { } void JSModalDialogViews::CloseAppModalDialog() { - window()->CloseWindow(); + window()->Close(); } void JSModalDialogViews::AcceptAppModalDialog() { diff --git a/chrome/browser/ui/views/native_constrained_window_win.cc b/chrome/browser/ui/views/native_constrained_window_win.cc index bf7e21c..134e87b 100644 --- a/chrome/browser/ui/views/native_constrained_window_win.cc +++ b/chrome/browser/ui/views/native_constrained_window_win.cc @@ -16,7 +16,8 @@ class NativeConstrainedWindowWin : public NativeConstrainedWindow, public views::WindowWin { public: explicit NativeConstrainedWindowWin(NativeConstrainedWindowDelegate* delegate) - : delegate_(delegate) { + : views::WindowWin(delegate->AsNativeWindowDelegate()), + delegate_(delegate) { } virtual ~NativeConstrainedWindowWin() { @@ -41,11 +42,6 @@ class NativeConstrainedWindowWin : public NativeConstrainedWindow, return WindowWin::OnMouseActivate(message, w_param, l_param); } - // Overridden from views::Window: - virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE { - return delegate_->CreateFrameViewForWindow(); - } - NativeConstrainedWindowDelegate* delegate_; DISALLOW_COPY_AND_ASSIGN(NativeConstrainedWindowWin); diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc index f403913..4cf5569 100644 --- a/chrome/browser/ui/views/notifications/balloon_view.cc +++ b/chrome/browser/ui/views/notifications/balloon_view.cc @@ -316,21 +316,21 @@ void BalloonViewImpl::Show(Balloon* balloon) { gfx::Rect contents_rect = GetContentsRectangle(); html_contents_.reset(new BalloonViewHost(balloon)); html_contents_->SetPreferredSize(gfx::Size(10000, 10000)); - html_container_ = Widget::CreateWidget(); - html_container_->SetAlwaysOnTop(true); + html_container_ = new Widget; Widget::InitParams params(Widget::InitParams::TYPE_POPUP); params.bounds = contents_rect; html_container_->Init(params); html_container_->SetContentsView(html_contents_->view()); + html_container_->SetAlwaysOnTop(true); gfx::Rect balloon_rect(x(), y(), GetTotalWidth(), GetTotalHeight()); - frame_container_ = Widget::CreateWidget(); + frame_container_ = new Widget; frame_container_->set_widget_delegate(this); - frame_container_->SetAlwaysOnTop(true); params.transparent = true; params.bounds = balloon_rect; frame_container_->Init(params); frame_container_->SetContentsView(this); + frame_container_->SetAlwaysOnTop(true); frame_container_->MoveAboveWidget(html_container_); close_button_->SetImage(views::CustomButton::BS_NORMAL, diff --git a/chrome/browser/ui/views/profile_tag_view.cc b/chrome/browser/ui/views/profile_tag_view.cc index 97a03e8..ed96923 100644 --- a/chrome/browser/ui/views/profile_tag_view.cc +++ b/chrome/browser/ui/views/profile_tag_view.cc @@ -77,7 +77,7 @@ void ProfileTagView::CreateProfileTagBitmaps() { return; profile_tag_bitmaps_created_ = true; - ui::ThemeProvider* theme_provider = frame_->GetThemeProviderForFrame(); + ui::ThemeProvider* theme_provider = frame_->GetThemeProvider(); bool aero = theme_provider->ShouldUseNativeFrame(); SkBitmap* profile_tag_center = aero ? theme_provider->GetBitmapNamed(IDR_PROFILE_TAG_CENTER_AERO) : diff --git a/chrome/browser/ui/views/status_bubble_views.cc b/chrome/browser/ui/views/status_bubble_views.cc index cc6a345..2a24177 100644 --- a/chrome/browser/ui/views/status_bubble_views.cc +++ b/chrome/browser/ui/views/status_bubble_views.cc @@ -558,19 +558,19 @@ StatusBubbleViews::~StatusBubbleViews() { void StatusBubbleViews::Init() { if (!popup_.get()) { - popup_.reset(Widget::CreateWidget()); + popup_.reset(new Widget); views::Widget* frame = base_view_->GetWidget(); if (!view_) view_ = new StatusView(this, popup_.get(), frame->GetThemeProvider()); if (!expand_view_.get()) expand_view_.reset(new StatusViewExpander(this, view_)); - popup_->SetOpacity(0x00); Widget::InitParams params(Widget::InitParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; params.delete_on_destroy = false; params.parent = frame->GetNativeView(); popup_->Init(params); + popup_->SetOpacity(0x00); popup_->SetContentsView(view_); Reposition(); popup_->Show(); @@ -794,7 +794,7 @@ bool StatusBubbleViews::IsFrameVisible() { if (!frame->IsVisible()) return false; - views::Window* window = frame->GetWindow(); + views::Window* window = frame->GetContainingWindow(); return !window || !window->IsMinimized(); } diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc index 6ac2a5b8..ce63670 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc @@ -6,6 +6,7 @@ #include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" +#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" #include "content/browser/renderer_host/render_widget_host_view.h" #include "content/browser/tab_contents/interstitial_page.h" #include "content/browser/tab_contents/tab_contents.h" @@ -37,6 +38,8 @@ void NativeTabContentsContainerGtk::DetachContents(TabContents* contents) { // Now detach the TabContents. Detach(); + + static_cast<TabContentsViewViews*>(contents->view())->Unparent(); } void NativeTabContentsContainerGtk::SetFastResize(bool fast_resize) { diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h index d3e63ba..680aac6 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h @@ -7,9 +7,14 @@ #pragma once class TabContents; -namespace gfx{ +namespace gfx { class Size; } +namespace views { +namespace internal { +class NativeWidgetDelegate; +} +} namespace internal { @@ -30,14 +35,16 @@ class NativeTabContentsViewDelegate { virtual void OnNativeTabContentsViewHidden() = 0; virtual void OnNativeTabContentsViewSized(const gfx::Size& size) = 0; - virtual void OnNativeTabContentsViewWheelZoom(int distance) = 0; + virtual void OnNativeTabContentsViewWheelZoom(bool zoom_in) = 0; // TODO(beng): // These two can be replaced by an override of Widget::OnMouseEvent. virtual void OnNativeTabContentsViewMouseDown() = 0; - virtual void OnNativeTabContentsViewMouseMove() = 0; + virtual void OnNativeTabContentsViewMouseMove(bool motion) = 0; virtual void OnNativeTabContentsViewDraggingEnded() = 0; + + virtual views::internal::NativeWidgetDelegate* AsNativeWidgetDelegate() = 0; }; } // namespace internal diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc new file mode 100644 index 0000000..f3a3198 --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc @@ -0,0 +1,846 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h" + +#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" +#include "chrome/browser/tab_contents/web_drag_dest_gtk.h" +#include "chrome/browser/ui/gtk/constrained_window_gtk.h" +#include "chrome/browser/ui/gtk/tab_contents_drag_source.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" + +using WebKit::WebDragOperation; +using WebKit::WebDragOperationsMask; +using WebKit::WebInputEvent; + +namespace { + +// Called when the content view gtk widget is tabbed to, or after the call to +// gtk_widget_child_focus() in TakeFocus(). We return true +// and grab focus if we don't have it. The call to +// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to +// webkit. +gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, + TabContents* tab_contents) { + // If we already have focus, let the next widget have a shot at it. We will + // reach this situation after the call to gtk_widget_child_focus() in + // TakeFocus(). + if (gtk_widget_is_focus(widget)) + return FALSE; + + gtk_widget_grab_focus(widget); + bool reverse = focus == GTK_DIR_TAB_BACKWARD; + tab_contents->FocusThroughTabTraversal(reverse); + return TRUE; +} + +// See tab_contents_view_gtk.cc for discussion of mouse scroll zooming. +gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event, + internal::NativeTabContentsViewDelegate* delegate) { + if ((event->state & gtk_accelerator_get_default_mod_mask()) == + GDK_CONTROL_MASK) { + if (event->direction == GDK_SCROLL_DOWN) { + delegate->OnNativeTabContentsViewWheelZoom(false); + return TRUE; + } + if (event->direction == GDK_SCROLL_UP) { + delegate->OnNativeTabContentsViewWheelZoom(true); + return TRUE; + } + } + + return FALSE; +} + +gfx::NativeView GetHiddenTabHostWindow() { + static views::Widget* widget = NULL; + + if (!widget) { + widget = new views::Widget; + // We don't want this widget to be closed automatically, this causes + // problems in tests that close the last non-secondary window. + widget->set_is_secondary_widget(false); + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); + widget->Init(params); + } + + return static_cast<views::WidgetGtk*>(widget->native_widget())-> + window_contents(); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, public: + +NativeTabContentsViewGtk::NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate) + : views::WidgetGtk(delegate->AsNativeWidgetDelegate()), + delegate_(delegate), + ignore_next_char_event_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(drag_source_( + new TabContentsDragSource(delegate->GetTabContents()->view()))) { +} + +NativeTabContentsViewGtk::~NativeTabContentsViewGtk() { + delegate_ = NULL; + CloseNow(); +} + +void NativeTabContentsViewGtk::AttachConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window) == constrained_windows_.end()); + + constrained_windows_.push_back(constrained_window); + AddChild(constrained_window->widget()); + + gfx::Size requested_size; + views::WidgetGtk::GetRequestedSize(&requested_size); + PositionConstrainedWindows(requested_size); +} + +void NativeTabContentsViewGtk::RemoveConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + std::vector<ConstrainedWindowGtk*>::iterator item = + find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window); + DCHECK(item != constrained_windows_.end()); + RemoveChild((*item)->widget()); + constrained_windows_.erase(item); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, NativeTabContentsView implementation: + +void NativeTabContentsViewGtk::InitNativeTabContentsView() { + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; + params.delete_on_destroy = false; + GetWidget()->Init(params); + + // We need to own the widget in order to attach/detach the native view to a + // container. + gtk_object_ref(GTK_OBJECT(GetWidget()->GetNativeView())); +} + +void NativeTabContentsViewGtk::Unparent() { + // Note that we do not DCHECK on focus_manager_ as it may be NULL when used + // with an external tab container. + NativeWidget::ReparentNativeView(GetNativeView(), GetHiddenTabHostWindow()); +} + +RenderWidgetHostView* NativeTabContentsViewGtk::CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) { + RenderWidgetHostViewGtk* view = + new RenderWidgetHostViewGtk(render_widget_host); + view->InitAsChild(); + g_signal_connect(view->native_view(), "focus", + G_CALLBACK(OnFocus), delegate_->GetTabContents()); + g_signal_connect(view->native_view(), "scroll-event", + G_CALLBACK(OnMouseScroll), delegate_); + + // Let widget know that the tab contents has been painted. + views::WidgetGtk::RegisterChildExposeHandler(view->native_view()); + + // Renderer target DnD. + if (delegate_->GetTabContents()->ShouldAcceptDragAndDrop()) + drag_dest_.reset(new WebDragDestGtk(delegate_->GetTabContents(), + view->native_view())); + + gtk_fixed_put(GTK_FIXED(GetWidget()->GetNativeView()), view->native_view(), 0, + 0); + return view; +} + +gfx::NativeWindow NativeTabContentsViewGtk::GetTopLevelNativeWindow() const { + GtkWidget* window = gtk_widget_get_ancestor(GetWidget()->GetNativeView(), + GTK_TYPE_WINDOW); + return window ? GTK_WINDOW(window) : NULL; +} + +void NativeTabContentsViewGtk::SetPageTitle(const std::wstring& title) { + // Set the window name to include the page title so it's easier to spot + // when debugging (e.g. via xwininfo -tree). + if (GDK_IS_WINDOW(GetNativeView()->window)) + gdk_window_set_title(GetNativeView()->window, WideToUTF8(title).c_str()); +} + +void NativeTabContentsViewGtk::StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { + drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, + image, image_offset); +} + +void NativeTabContentsViewGtk::CancelDrag() { +} + +bool NativeTabContentsViewGtk::IsDoingDrag() const { + return false; +} + +void NativeTabContentsViewGtk::SetDragCursor( + WebKit::WebDragOperation operation) { + if (drag_dest_.get()) + drag_dest_->UpdateDragStatus(operation); +} + +views::NativeWidget* NativeTabContentsViewGtk::AsNativeWidget() { + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, views::WidgetGtk overrides: + +// Called when the mouse moves within the widget. We notify SadTabView if it's +// not NULL, else our delegate. +gboolean NativeTabContentsViewGtk::OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnMotionNotify(widget, event); + + delegate_->OnNativeTabContentsViewMouseMove(true); + return FALSE; +} + +gboolean NativeTabContentsViewGtk::OnLeaveNotify(GtkWidget* widget, + GdkEventCrossing* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnLeaveNotify(widget, event); + + delegate_->OnNativeTabContentsViewMouseMove(false); + return FALSE; +} + +gboolean NativeTabContentsViewGtk::OnButtonPress(GtkWidget* widget, + GdkEventButton* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnButtonPress(widget, event); + last_mouse_down_ = *event; + return views::WidgetGtk::OnButtonPress(widget, event); +} + +void NativeTabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) { + gfx::Size size(allocation->width, allocation->height); + delegate_->OnNativeTabContentsViewSized(size); + if (size != size_) + PositionConstrainedWindows(size); + size_ = size; + views::WidgetGtk::OnSizeAllocate(widget, allocation); +} + +void NativeTabContentsViewGtk::OnShow(GtkWidget* widget) { + delegate_->OnNativeTabContentsViewShown(); + views::WidgetGtk::OnShow(widget); +} + +void NativeTabContentsViewGtk::OnHide(GtkWidget* widget) { + // OnHide can be called during widget destruction (gtk_widget_dispose calls + // gtk_widget_hide) so we make sure we do not call back through to the + // delegate after it's already deleted. + if (delegate_) + delegate_->OnNativeTabContentsViewHidden(); + views::WidgetGtk::OnHide(widget); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, private: + +void NativeTabContentsViewGtk::PositionConstrainedWindows( + const gfx::Size& view_size) { + // Place each ConstrainedWindow in the center of the view. + int half_view_width = view_size.width() / 2; + + typedef std::vector<ConstrainedWindowGtk*>::iterator iterator; + + for (iterator f = constrained_windows_.begin(), + l = constrained_windows_.end(); f != l; ++f) { + GtkWidget* widget = (*f)->widget(); + + GtkRequisition requisition; + gtk_widget_size_request(widget, &requisition); + + int child_x = std::max(half_view_width - (requisition.width / 2), 0); + PositionChild(widget, child_x, 0, 0, 0); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsView, public: + +// static +NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( + internal::NativeTabContentsViewDelegate* delegate) { + return new NativeTabContentsViewGtk(delegate); +} + +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h" + +#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" +#include "chrome/browser/tab_contents/web_drag_dest_gtk.h" +#include "chrome/browser/ui/gtk/constrained_window_gtk.h" +#include "chrome/browser/ui/gtk/tab_contents_drag_source.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" + +using WebKit::WebDragOperation; +using WebKit::WebDragOperationsMask; +using WebKit::WebInputEvent; + +namespace { + +// Called when the content view gtk widget is tabbed to, or after the call to +// gtk_widget_child_focus() in TakeFocus(). We return true +// and grab focus if we don't have it. The call to +// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to +// webkit. +gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, + TabContents* tab_contents) { + // If we already have focus, let the next widget have a shot at it. We will + // reach this situation after the call to gtk_widget_child_focus() in + // TakeFocus(). + if (gtk_widget_is_focus(widget)) + return FALSE; + + gtk_widget_grab_focus(widget); + bool reverse = focus == GTK_DIR_TAB_BACKWARD; + tab_contents->FocusThroughTabTraversal(reverse); + return TRUE; +} + +// See tab_contents_view_gtk.cc for discussion of mouse scroll zooming. +gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event, + internal::NativeTabContentsViewDelegate* delegate) { + if ((event->state & gtk_accelerator_get_default_mod_mask()) == + GDK_CONTROL_MASK) { + if (event->direction == GDK_SCROLL_DOWN) { + delegate->OnNativeTabContentsViewWheelZoom(false); + return TRUE; + } + if (event->direction == GDK_SCROLL_UP) { + delegate->OnNativeTabContentsViewWheelZoom(true); + return TRUE; + } + } + + return FALSE; +} + +gfx::NativeView GetHiddenTabHostWindow() { + static views::Widget* widget = NULL; + + if (!widget) { + widget = new views::Widget; + // We don't want this widget to be closed automatically, this causes + // problems in tests that close the last non-secondary window. + widget->set_is_secondary_widget(false); + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); + widget->Init(params); + } + + return static_cast<views::WidgetGtk*>(widget->native_widget())-> + window_contents(); +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, public: + +NativeTabContentsViewGtk::NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate) + : views::WidgetGtk(delegate->AsNativeWidgetDelegate()), + delegate_(delegate), + ignore_next_char_event_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(drag_source_( + new TabContentsDragSource(delegate->GetTabContents()->view()))) { +} + +NativeTabContentsViewGtk::~NativeTabContentsViewGtk() { + delegate_ = NULL; + CloseNow(); +} + +void NativeTabContentsViewGtk::AttachConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window) == constrained_windows_.end()); + + constrained_windows_.push_back(constrained_window); + AddChild(constrained_window->widget()); + + gfx::Size requested_size; + views::WidgetGtk::GetRequestedSize(&requested_size); + PositionConstrainedWindows(requested_size); +} + +void NativeTabContentsViewGtk::RemoveConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + std::vector<ConstrainedWindowGtk*>::iterator item = + find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window); + DCHECK(item != constrained_windows_.end()); + RemoveChild((*item)->widget()); + constrained_windows_.erase(item); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, NativeTabContentsView implementation: + +void NativeTabContentsViewGtk::InitNativeTabContentsView() { + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; + params.delete_on_destroy = false; + GetWidget()->Init(params); + + // We need to own the widget in order to attach/detach the native view to a + // container. + gtk_object_ref(GTK_OBJECT(GetWidget()->GetNativeView())); +} + +void NativeTabContentsViewGtk::Unparent() { + // Note that we do not DCHECK on focus_manager_ as it may be NULL when used + // with an external tab container. + NativeWidget::ReparentNativeView(GetNativeView(), GetHiddenTabHostWindow()); +} + +RenderWidgetHostView* NativeTabContentsViewGtk::CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) { + RenderWidgetHostViewGtk* view = + new RenderWidgetHostViewGtk(render_widget_host); + view->InitAsChild(); + g_signal_connect(view->native_view(), "focus", + G_CALLBACK(OnFocus), delegate_->GetTabContents()); + g_signal_connect(view->native_view(), "scroll-event", + G_CALLBACK(OnMouseScroll), delegate_); + + // Let widget know that the tab contents has been painted. + views::WidgetGtk::RegisterChildExposeHandler(view->native_view()); + + // Renderer target DnD. + if (delegate_->GetTabContents()->ShouldAcceptDragAndDrop()) + drag_dest_.reset(new WebDragDestGtk(delegate_->GetTabContents(), + view->native_view())); + + gtk_fixed_put(GTK_FIXED(GetWidget()->GetNativeView()), view->native_view(), 0, + 0); + return view; +} + +gfx::NativeWindow NativeTabContentsViewGtk::GetTopLevelNativeWindow() const { + GtkWidget* window = gtk_widget_get_ancestor(GetWidget()->GetNativeView(), + GTK_TYPE_WINDOW); + return window ? GTK_WINDOW(window) : NULL; +} + +void NativeTabContentsViewGtk::SetPageTitle(const std::wstring& title) { + // Set the window name to include the page title so it's easier to spot + // when debugging (e.g. via xwininfo -tree). + if (GDK_IS_WINDOW(GetNativeView()->window)) + gdk_window_set_title(GetNativeView()->window, WideToUTF8(title).c_str()); +} + +void NativeTabContentsViewGtk::StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { + drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, + image, image_offset); +} + +void NativeTabContentsViewGtk::CancelDrag() { +} + +bool NativeTabContentsViewGtk::IsDoingDrag() const { + return false; +} + +void NativeTabContentsViewGtk::SetDragCursor( + WebKit::WebDragOperation operation) { + if (drag_dest_.get()) + drag_dest_->UpdateDragStatus(operation); +} + +views::NativeWidget* NativeTabContentsViewGtk::AsNativeWidget() { + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, views::WidgetGtk overrides: + +// Called when the mouse moves within the widget. We notify SadTabView if it's +// not NULL, else our delegate. +gboolean NativeTabContentsViewGtk::OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnMotionNotify(widget, event); + + delegate_->OnNativeTabContentsViewMouseMove(true); + return FALSE; +} + +gboolean NativeTabContentsViewGtk::OnLeaveNotify(GtkWidget* widget, + GdkEventCrossing* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnLeaveNotify(widget, event); + + delegate_->OnNativeTabContentsViewMouseMove(false); + return FALSE; +} + +gboolean NativeTabContentsViewGtk::OnButtonPress(GtkWidget* widget, + GdkEventButton* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnButtonPress(widget, event); + last_mouse_down_ = *event; + return views::WidgetGtk::OnButtonPress(widget, event); +} + +void NativeTabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) { + gfx::Size size(allocation->width, allocation->height); + delegate_->OnNativeTabContentsViewSized(size); + if (size != size_) + PositionConstrainedWindows(size); + size_ = size; + views::WidgetGtk::OnSizeAllocate(widget, allocation); +} + +void NativeTabContentsViewGtk::OnShow(GtkWidget* widget) { + delegate_->OnNativeTabContentsViewShown(); + views::WidgetGtk::OnShow(widget); +} + +void NativeTabContentsViewGtk::OnHide(GtkWidget* widget) { + // OnHide can be called during widget destruction (gtk_widget_dispose calls + // gtk_widget_hide) so we make sure we do not call back through to the + // delegate after it's already deleted. + if (delegate_) + delegate_->OnNativeTabContentsViewHidden(); + views::WidgetGtk::OnHide(widget); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, private: + +void NativeTabContentsViewGtk::PositionConstrainedWindows( + const gfx::Size& view_size) { + // Place each ConstrainedWindow in the center of the view. + int half_view_width = view_size.width() / 2; + + typedef std::vector<ConstrainedWindowGtk*>::iterator iterator; + + for (iterator f = constrained_windows_.begin(), + l = constrained_windows_.end(); f != l; ++f) { + GtkWidget* widget = (*f)->widget(); + + GtkRequisition requisition; + gtk_widget_size_request(widget, &requisition); + + int child_x = std::max(half_view_width - (requisition.width / 2), 0); + PositionChild(widget, child_x, 0, 0, 0); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsView, public: + +// static +NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( + internal::NativeTabContentsViewDelegate* delegate) { + return new NativeTabContentsViewGtk(delegate); +} + +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h" + +#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" +#include "chrome/browser/tab_contents/web_drag_dest_gtk.h" +#include "chrome/browser/ui/gtk/constrained_window_gtk.h" +#include "chrome/browser/ui/gtk/tab_contents_drag_source.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" + +using WebKit::WebDragOperation; +using WebKit::WebDragOperationsMask; +using WebKit::WebInputEvent; + +namespace { + +/* +// Called when the content view gtk widget is tabbed to, or after the call to +// gtk_widget_child_focus() in TakeFocus(). We return true +// and grab focus if we don't have it. The call to +// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to +// webkit. +gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, + TabContents* tab_contents) { + // If we already have focus, let the next widget have a shot at it. We will + // reach this situation after the call to gtk_widget_child_focus() in + // TakeFocus(). + if (gtk_widget_is_focus(widget)) + return FALSE; + + gtk_widget_grab_focus(widget); + bool reverse = focus == GTK_DIR_TAB_BACKWARD; + tab_contents->FocusThroughTabTraversal(reverse); + return TRUE; +} + +// Called when the mouse leaves the widget. We notify our delegate. +// WidgetGtk also defines OnLeaveNotify, so we use the name OnLeaveNotify2 +// here. +gboolean OnLeaveNotify2(GtkWidget* widget, GdkEventCrossing* event, + TabContents* tab_contents) { + if (tab_contents->delegate()) + tab_contents->delegate()->ContentsMouseEvent( + tab_contents, views::Screen::GetCursorScreenPoint(), false); + return FALSE; +} + +// Called when the mouse moves within the widget. +gboolean CallMouseMove(GtkWidget* widget, GdkEventMotion* event, + TabContentsViewGtk* tab_contents_view) { + return tab_contents_view->OnMouseMove(widget, event); +} + +// See tab_contents_view_gtk.cc for discussion of mouse scroll zooming. +gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event, + TabContents* tab_contents) { + if ((event->state & gtk_accelerator_get_default_mod_mask()) == + GDK_CONTROL_MASK) { + if (tab_contents->delegate()) { + if (event->direction == GDK_SCROLL_DOWN) { + tab_contents->delegate()->ContentsZoomChange(false); + return TRUE; + } else if (event->direction == GDK_SCROLL_UP) { + tab_contents->delegate()->ContentsZoomChange(true); + return TRUE; + } + } + } + + return FALSE; +} +*/ + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, public: + +NativeTabContentsViewGtk::NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate) + : views::WidgetGtk(delegate->AsNativeWidgetDelegate()), + delegate_(delegate), + ignore_next_char_event_(false), + ALLOW_THIS_IN_INITIALIZER_LIST(drag_source_( + new TabContentsDragSource(delegate->GetTabContents()->view()))) { +} + +NativeTabContentsViewGtk::~NativeTabContentsViewGtk() { + CloseNow(); +} + +void NativeTabContentsViewGtk::AttachConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window) == constrained_windows_.end()); + + constrained_windows_.push_back(constrained_window); + AddChild(constrained_window->widget()); + + gfx::Size requested_size; + views::WidgetGtk::GetRequestedSize(&requested_size); + PositionConstrainedWindows(requested_size); +} + +void NativeTabContentsViewGtk::RemoveConstrainedWindow( + ConstrainedWindowGtk* constrained_window) { + std::vector<ConstrainedWindowGtk*>::iterator item = + find(constrained_windows_.begin(), constrained_windows_.end(), + constrained_window); + DCHECK(item != constrained_windows_.end()); + RemoveChild((*item)->widget()); + constrained_windows_.erase(item); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, NativeTabContentsView implementation: + +void NativeTabContentsViewGtk::InitNativeTabContentsView() { + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; + params.delete_on_destroy = false; + GetWidget()->Init(params); + + // We need to own the widget in order to attach/detach the native view to a + // container. + gtk_object_ref(GTK_OBJECT(GetWidget()->GetNativeView())); +} + +void NativeTabContentsViewGtk::Unparent() { +} + +RenderWidgetHostView* NativeTabContentsViewGtk::CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) { + RenderWidgetHostViewGtk* view = + new RenderWidgetHostViewGtk(render_widget_host); + view->InitAsChild(); + /* + g_signal_connect(view->native_view(), "focus", + G_CALLBACK(OnFocus), delegate_->GetTabContents()); + g_signal_connect(view->native_view(), "leave-notify-event", + G_CALLBACK(OnLeaveNotify2), delegate_->GetTabContents()); + g_signal_connect(view->native_view(), "motion-notify-event", + G_CALLBACK(CallMouseMove), this); + g_signal_connect(view->native_view(), "scroll-event", + G_CALLBACK(OnMouseScroll), delegate_->GetTabContents()); + */ + gtk_widget_add_events(view->native_view(), GDK_LEAVE_NOTIFY_MASK | + GDK_POINTER_MOTION_MASK); + + // Let widget know that the tab contents has been painted. + views::WidgetGtk::RegisterChildExposeHandler(view->native_view()); + + // Renderer target DnD. + if (delegate_->GetTabContents()->ShouldAcceptDragAndDrop()) + drag_dest_.reset(new WebDragDestGtk(delegate_->GetTabContents(), + view->native_view())); + + gtk_fixed_put(GTK_FIXED(GetWidget()->GetNativeView()), view->native_view(), 0, + 0); + return view; +} + +gfx::NativeWindow NativeTabContentsViewGtk::GetTopLevelNativeWindow() const { + GtkWidget* window = gtk_widget_get_ancestor(GetWidget()->GetNativeView(), + GTK_TYPE_WINDOW); + return window ? GTK_WINDOW(window) : NULL; +} + +void NativeTabContentsViewGtk::SetPageTitle(const std::wstring& title) { + // Set the window name to include the page title so it's easier to spot + // when debugging (e.g. via xwininfo -tree). + gdk_window_set_title(GetNativeView()->window, WideToUTF8(title).c_str()); +} + +void NativeTabContentsViewGtk::StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { + drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, + image, image_offset); +} + +void NativeTabContentsViewGtk::CancelDrag() { +} + +bool NativeTabContentsViewGtk::IsDoingDrag() const { + return false; +} + +void NativeTabContentsViewGtk::SetDragCursor( + WebKit::WebDragOperation operation) { + if (drag_dest_.get()) + drag_dest_->UpdateDragStatus(operation); +} + +views::NativeWidget* NativeTabContentsViewGtk::AsNativeWidget() { + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, views::WidgetGtk overrides: + +// Called when the mouse moves within the widget. We notify SadTabView if it's +// not NULL, else our delegate. +gboolean NativeTabContentsViewGtk::OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnMotionNotify(widget, event); + + delegate_->OnNativeTabContentsViewMouseMove(); + return FALSE; +} + +gboolean NativeTabContentsViewGtk::OnButtonPress(GtkWidget* widget, + GdkEventButton* event) { + if (delegate_->IsShowingSadTab()) + return views::WidgetGtk::OnButtonPress(widget, event); + last_mouse_down_ = *event; + return views::WidgetGtk::OnButtonPress(widget, event); +} + +void NativeTabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) { + gfx::Size size(allocation->width, allocation->height); + delegate_->OnNativeTabContentsViewSized(size); + if (size != size_) + PositionConstrainedWindows(size); + size_ = size; + views::WidgetGtk::OnSizeAllocate(widget, allocation); +} + +void NativeTabContentsViewGtk::OnShow(GtkWidget* widget) { + delegate_->OnNativeTabContentsViewShown(); + views::WidgetGtk::OnShow(widget); +} + +void NativeTabContentsViewGtk::OnHide(GtkWidget* widget) { + delegate_->OnNativeTabContentsViewHidden(); + views::WidgetGtk::OnHide(widget); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewGtk, private: + +void NativeTabContentsViewGtk::PositionConstrainedWindows( + const gfx::Size& view_size) { + // Place each ConstrainedWindow in the center of the view. + int half_view_width = view_size.width() / 2; + + typedef std::vector<ConstrainedWindowGtk*>::iterator iterator; + + for (iterator f = constrained_windows_.begin(), + l = constrained_windows_.end(); f != l; ++f) { + GtkWidget* widget = (*f)->widget(); + + GtkRequisition requisition; + gtk_widget_size_request(widget, &requisition); + + int child_x = std::max(half_view_width - (requisition.width / 2), 0); + PositionChild(widget, child_x, 0, 0, 0); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsView, public: + +// static +NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( + internal::NativeTabContentsViewDelegate* delegate) { + return new NativeTabContentsViewGtk(delegate); +} + diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h new file mode 100644 index 0000000..cbdbe5c --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.h @@ -0,0 +1,259 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" +#include "views/widget/widget_gtk.h" + +class ConstrainedWindowGtk; +class TabContents; +class TabContentsDragSource; +class WebDragDestGtk; + +class NativeTabContentsViewGtk : public views::WidgetGtk, + public NativeTabContentsView { + public: + explicit NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate); + virtual ~NativeTabContentsViewGtk(); + + // Unlike Windows, ConstrainedWindows need to collaborate with the + // TabContentsViewGtk to position the dialogs. + void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window); + void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window); + + + private: + // Overridden from NativeTabContentsView: + virtual void InitNativeTabContentsView() OVERRIDE; + virtual void Unparent() OVERRIDE; + virtual RenderWidgetHostView* CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void SetPageTitle(const std::wstring& title) OVERRIDE; + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) OVERRIDE; + virtual void CancelDrag() OVERRIDE; + virtual bool IsDoingDrag() const OVERRIDE; + virtual void SetDragCursor(WebKit::WebDragOperation operation) OVERRIDE; + virtual views::NativeWidget* AsNativeWidget() OVERRIDE; + + // Overridden from views::WidgetGtk: + virtual gboolean OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) OVERRIDE; + virtual gboolean OnLeaveNotify(GtkWidget* widget, + GdkEventCrossing* event) OVERRIDE; + virtual gboolean OnButtonPress(GtkWidget* widget, + GdkEventButton* event) OVERRIDE; + virtual void OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) OVERRIDE; + virtual void OnShow(GtkWidget* widget) OVERRIDE; + virtual void OnHide(GtkWidget* widget) OVERRIDE; + + void PositionConstrainedWindows(const gfx::Size& view_size); + + internal::NativeTabContentsViewDelegate* delegate_; + + // Whether to ignore the next CHAR keyboard event. + bool ignore_next_char_event_; + + // Handles drags from this TabContentsView. + scoped_ptr<TabContentsDragSource> drag_source_; + + // The event for the last mouse down we handled. We need this for drags. + GdkEventButton last_mouse_down_; + + // The helper object that handles drag destination related interactions with + // GTK. + scoped_ptr<WebDragDestGtk> drag_dest_; + + // Current size. See comment in WidgetGtk as to why this is cached. + gfx::Size size_; + + // Each individual UI for constrained dialogs currently displayed. The + // objects in this vector are owned by the TabContents, not the view. + std::vector<ConstrainedWindowGtk*> constrained_windows_; + + DISALLOW_COPY_AND_ASSIGN(NativeTabContentsViewGtk); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ + +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" +#include "views/widget/widget_gtk.h" + +class ConstrainedWindowGtk; +class TabContents; +class TabContentsDragSource; +class WebDragDestGtk; + +class NativeTabContentsViewGtk : public views::WidgetGtk, + public NativeTabContentsView { + public: + explicit NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate); + virtual ~NativeTabContentsViewGtk(); + + // Unlike Windows, ConstrainedWindows need to collaborate with the + // TabContentsViewGtk to position the dialogs. + void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window); + void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window); + + + private: + // Overridden from NativeTabContentsView: + virtual void InitNativeTabContentsView() OVERRIDE; + virtual void Unparent() OVERRIDE; + virtual RenderWidgetHostView* CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void SetPageTitle(const std::wstring& title) OVERRIDE; + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) OVERRIDE; + virtual void CancelDrag() OVERRIDE; + virtual bool IsDoingDrag() const OVERRIDE; + virtual void SetDragCursor(WebKit::WebDragOperation operation) OVERRIDE; + virtual views::NativeWidget* AsNativeWidget() OVERRIDE; + + // Overridden from views::WidgetGtk: + virtual gboolean OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) OVERRIDE; + virtual gboolean OnLeaveNotify(GtkWidget* widget, + GdkEventCrossing* event) OVERRIDE; + virtual gboolean OnButtonPress(GtkWidget* widget, + GdkEventButton* event) OVERRIDE; + virtual void OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) OVERRIDE; + virtual void OnShow(GtkWidget* widget) OVERRIDE; + virtual void OnHide(GtkWidget* widget) OVERRIDE; + + void PositionConstrainedWindows(const gfx::Size& view_size); + + internal::NativeTabContentsViewDelegate* delegate_; + + // Whether to ignore the next CHAR keyboard event. + bool ignore_next_char_event_; + + // Handles drags from this TabContentsView. + scoped_ptr<TabContentsDragSource> drag_source_; + + // The event for the last mouse down we handled. We need this for drags. + GdkEventButton last_mouse_down_; + + // The helper object that handles drag destination related interactions with + // GTK. + scoped_ptr<WebDragDestGtk> drag_dest_; + + // Current size. See comment in WidgetGtk as to why this is cached. + gfx::Size size_; + + // Each individual UI for constrained dialogs currently displayed. The + // objects in this vector are owned by the TabContents, not the view. + std::vector<ConstrainedWindowGtk*> constrained_windows_; + + DISALLOW_COPY_AND_ASSIGN(NativeTabContentsViewGtk); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ + +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" +#include "views/widget/widget_gtk.h" + +class ConstrainedWindowGtk; +class TabContents; +class TabContentsDragSource; +class WebDragDestGtk; + +class NativeTabContentsViewGtk : public views::WidgetGtk, + public NativeTabContentsView { + public: + explicit NativeTabContentsViewGtk( + internal::NativeTabContentsViewDelegate* delegate); + virtual ~NativeTabContentsViewGtk(); + + // Unlike Windows, ConstrainedWindows need to collaborate with the + // TabContentsViewGtk to position the dialogs. + void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window); + void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window); + + + private: + // Overridden from NativeTabContentsView: + virtual void InitNativeTabContentsView() OVERRIDE; + virtual void Unparent() OVERRIDE; + virtual RenderWidgetHostView* CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void SetPageTitle(const std::wstring& title) OVERRIDE; + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) OVERRIDE; + virtual void CancelDrag() OVERRIDE; + virtual bool IsDoingDrag() const OVERRIDE; + virtual void SetDragCursor(WebKit::WebDragOperation operation) OVERRIDE; + virtual views::NativeWidget* AsNativeWidget() OVERRIDE; + + // Overridden from views::WidgetGtk: + virtual gboolean OnMotionNotify(GtkWidget* widget, + GdkEventMotion* event) OVERRIDE; + virtual gboolean OnButtonPress(GtkWidget* widget, + GdkEventButton* event) OVERRIDE; + virtual void OnSizeAllocate(GtkWidget* widget, + GtkAllocation* allocation) OVERRIDE; + virtual void OnShow(GtkWidget* widget) OVERRIDE; + virtual void OnHide(GtkWidget* widget) OVERRIDE; + + void PositionConstrainedWindows(const gfx::Size& view_size); + + internal::NativeTabContentsViewDelegate* delegate_; + + // Whether to ignore the next CHAR keyboard event. + bool ignore_next_char_event_; + + // Handles drags from this TabContentsView. + scoped_ptr<TabContentsDragSource> drag_source_; + + // The event for the last mouse down we handled. We need this for drags. + GdkEventButton last_mouse_down_; + + // The helper object that handles drag destination related interactions with + // GTK. + scoped_ptr<WebDragDestGtk> drag_dest_; + + // Current size. See comment in WidgetGtk as to why this is cached. + gfx::Size size_; + + // Each individual UI for constrained dialogs currently displayed. The + // objects in this vector are owned by the TabContents, not the view. + std::vector<ConstrainedWindowGtk*> constrained_windows_; + + DISALLOW_COPY_AND_ASSIGN(NativeTabContentsViewGtk); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_GTK_H_ + diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc index 4f0bc23..9474fec 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc @@ -30,7 +30,10 @@ HWND GetHiddenTabHostWindow() { static views::Widget* widget = NULL; if (!widget) { - widget = views::Widget::CreateWidget(); + widget = new views::Widget; + // We don't want this widget to be closed automatically, this causes + // problems in tests that close the last non-secondary window. + widget->set_is_secondary_widget(false); views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); widget->Init(params); // If a background window requests focus, the hidden tab host will @@ -49,8 +52,8 @@ HWND GetHiddenTabHostWindow() { NativeTabContentsViewWin::NativeTabContentsViewWin( internal::NativeTabContentsViewDelegate* delegate) - : delegate_(delegate), - focus_manager_(NULL) { + : views::WidgetWin(delegate->AsNativeWidgetDelegate()), + delegate_(delegate) { } NativeTabContentsViewWin::~NativeTabContentsViewWin() { @@ -71,6 +74,7 @@ void NativeTabContentsViewWin::EndDragging() { void NativeTabContentsViewWin::InitNativeTabContentsView() { views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; params.delete_on_destroy = false; params.parent = GetHiddenTabHostWindow(); GetWidget()->Init(params); @@ -82,9 +86,6 @@ void NativeTabContentsViewWin::InitNativeTabContentsView() { } void NativeTabContentsViewWin::Unparent() { - // Remember who our FocusManager is, we won't be able to access it once - // unparented. - focus_manager_ = views::WidgetWin::GetFocusManager(); // Note that we do not DCHECK on focus_manager_ as it may be NULL when used // with an external tab container. NativeWidget::ReparentNativeView(GetNativeView(), GetHiddenTabHostWindow()); @@ -166,7 +167,7 @@ LRESULT NativeTabContentsViewWin::OnMouseRange(UINT msg, break; } case WM_MOUSEMOVE: - delegate_->OnNativeTabContentsViewMouseMove(); + delegate_->OnNativeTabContentsViewMouseMove(true); break; default: break; @@ -186,7 +187,7 @@ LRESULT NativeTabContentsViewWin::OnReflectedMessage(UINT msg, // This message is reflected from the view() to this window. if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) { delegate_->OnNativeTabContentsViewWheelZoom( - GET_WHEEL_DELTA_WPARAM(message->wParam)); + GET_WHEEL_DELTA_WPARAM(message->wParam) > 0); return 1; } break; @@ -263,22 +264,6 @@ void NativeTabContentsViewWin::OnNCPaint(HRGN rgn) { // here since the view will draw everything correctly. } -views::FocusManager* NativeTabContentsViewWin::GetFocusManager() { - views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); - if (focus_manager) { - // If focus_manager_ is non NULL, it means we have been reparented, in which - // case its value may not be valid anymore. - focus_manager_ = NULL; - return focus_manager; - } - // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be - // NULL. We are not doing it as it breaks some unit-tests. We should - // probably have an empty TabContentView implementation for the unit-tests, - // that would prevent that code being executed in the unit-test case. - // DCHECK(focus_manager_); - return focus_manager_; -} - //////////////////////////////////////////////////////////////////////////////// // NativeTabContentsViewWin, private: @@ -320,7 +305,7 @@ bool NativeTabContentsViewWin::ScrollZoom(int scroll_type) { break; } - delegate_->OnNativeTabContentsViewWheelZoom(distance); + delegate_->OnNativeTabContentsViewWheelZoom(distance > 0); return true; } return false; diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h index 4f8c60a..6b1f195 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.h @@ -61,7 +61,6 @@ class NativeTabContentsViewWin : public views::WidgetWin, virtual void OnSize(UINT param, const WTL::CSize& size) OVERRIDE; virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param) OVERRIDE; virtual void OnNCPaint(HRGN rgn) OVERRIDE; - virtual views::FocusManager* GetFocusManager() OVERRIDE; // Backend for all scroll messages, the |message| parameter indicates which // one it is. @@ -77,10 +76,6 @@ class NativeTabContentsViewWin : public views::WidgetWin, // Used to handle the drag-and-drop. scoped_refptr<TabContentsDragWin> drag_handler_; - // The FocusManager associated with this tab. Stored as it is not directly - // accessible when un-parented. - views::FocusManager* focus_manager_; - DISALLOW_COPY_AND_ASSIGN(NativeTabContentsViewWin); }; diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc deleted file mode 100644 index 6b8c426..0000000 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.cc +++ /dev/null @@ -1,488 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.h" - -#include <gdk/gdk.h> -#include <gtk/gtk.h> - -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "build/build_config.h" -#include "chrome/browser/download/download_shelf.h" -#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" -#include "chrome/browser/tab_contents/web_drag_dest_gtk.h" -#include "chrome/browser/ui/gtk/constrained_window_gtk.h" -#include "chrome/browser/ui/gtk/tab_contents_drag_source.h" -#include "chrome/browser/ui/views/sad_tab_view.h" -#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" -#include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/renderer_host/render_view_host_factory.h" -#include "content/browser/tab_contents/interstitial_page.h" -#include "content/browser/tab_contents/tab_contents.h" -#include "content/browser/tab_contents/tab_contents_delegate.h" -#include "ui/gfx/canvas_skia_paint.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" -#include "views/controls/native/native_view_host.h" -#include "views/focus/view_storage.h" -#include "views/screen.h" -#include "views/widget/root_view.h" -#include "views/widget/widget_gtk.h" - -using WebKit::WebDragOperation; -using WebKit::WebDragOperationsMask; -using WebKit::WebInputEvent; - - -namespace { - -// Called when the content view gtk widget is tabbed to, or after the call to -// gtk_widget_child_focus() in TakeFocus(). We return true -// and grab focus if we don't have it. The call to -// FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to -// webkit. -gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus, - TabContents* tab_contents) { - // If we already have focus, let the next widget have a shot at it. We will - // reach this situation after the call to gtk_widget_child_focus() in - // TakeFocus(). - if (gtk_widget_is_focus(widget)) - return FALSE; - - gtk_widget_grab_focus(widget); - bool reverse = focus == GTK_DIR_TAB_BACKWARD; - tab_contents->FocusThroughTabTraversal(reverse); - return TRUE; -} - -// Called when the mouse leaves the widget. We notify our delegate. -// WidgetGtk also defines OnLeaveNotify, so we use the name OnLeaveNotify2 -// here. -gboolean OnLeaveNotify2(GtkWidget* widget, GdkEventCrossing* event, - TabContents* tab_contents) { - if (tab_contents->delegate()) - tab_contents->delegate()->ContentsMouseEvent( - tab_contents, views::Screen::GetCursorScreenPoint(), false); - return FALSE; -} - -// Called when the mouse moves within the widget. -gboolean CallMouseMove(GtkWidget* widget, GdkEventMotion* event, - TabContentsViewGtk* tab_contents_view) { - return tab_contents_view->OnMouseMove(widget, event); -} - -// See tab_contents_view_gtk.cc for discussion of mouse scroll zooming. -gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event, - TabContents* tab_contents) { - if ((event->state & gtk_accelerator_get_default_mod_mask()) == - GDK_CONTROL_MASK) { - if (tab_contents->delegate()) { - if (event->direction == GDK_SCROLL_DOWN) { - tab_contents->delegate()->ContentsZoomChange(false); - return TRUE; - } else if (event->direction == GDK_SCROLL_UP) { - tab_contents->delegate()->ContentsZoomChange(true); - return TRUE; - } - } - } - - return FALSE; -} - -} // namespace - -// static -TabContentsView* TabContentsView::Create(TabContents* tab_contents) { - return new TabContentsViewGtk(tab_contents); -} - -TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) - : TabContentsView(tab_contents), - sad_tab_(NULL), - ignore_next_char_event_(false) { - drag_source_.reset(new TabContentsDragSource(this)); - last_focused_view_storage_id_ = - views::ViewStorage::GetInstance()->CreateStorageID(); -} - -TabContentsViewGtk::~TabContentsViewGtk() { - // Make sure to remove any stored view we may still have in the ViewStorage. - // - // It is possible the view went away before us, so we only do this if the - // view is registered. - views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); - if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) - view_storage->RemoveView(last_focused_view_storage_id_); - - // Just deleting the object doesn't destroy the GtkWidget. We need to do that - // manually, and synchronously, since subsequent signal handlers may expect - // to locate this object. - CloseNow(); -} - -void TabContentsViewGtk::AttachConstrainedWindow( - ConstrainedWindowGtk* constrained_window) { - DCHECK(find(constrained_windows_.begin(), constrained_windows_.end(), - constrained_window) == constrained_windows_.end()); - - constrained_windows_.push_back(constrained_window); - AddChild(constrained_window->widget()); - - gfx::Rect bounds; - GetContainerBounds(&bounds); - SetFloatingPosition(bounds.size()); -} - -void TabContentsViewGtk::RemoveConstrainedWindow( - ConstrainedWindowGtk* constrained_window) { - std::vector<ConstrainedWindowGtk*>::iterator item = - find(constrained_windows_.begin(), constrained_windows_.end(), - constrained_window); - DCHECK(item != constrained_windows_.end()); - RemoveChild((*item)->widget()); - constrained_windows_.erase(item); -} - -void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { - views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); - params.delete_on_destroy = false; - params.bounds = gfx::Rect(initial_size); - GetWidget()->Init(params); - // We need to own the widget in order to attach/detach the native view - // to container. - gtk_object_ref(GTK_OBJECT(GetNativeView())); -} - -RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( - RenderWidgetHost* render_widget_host) { - if (render_widget_host->view()) { - // During testing, the view will already be set up in most cases to the - // test view, so we don't want to clobber it with a real one. To verify that - // this actually is happening (and somebody isn't accidentally creating the - // view twice), we check for the RVH Factory, which will be set when we're - // making special ones (which go along with the special views). - DCHECK(RenderViewHostFactory::has_factory()); - return render_widget_host->view(); - } - - // If we were showing sad tab, remove it now. - if (sad_tab_ != NULL) { - SetContentsView(new views::View()); - sad_tab_ = NULL; - } - - RenderWidgetHostViewGtk* view = - new RenderWidgetHostViewGtk(render_widget_host); - view->InitAsChild(); - g_signal_connect(view->native_view(), "focus", - G_CALLBACK(OnFocus), tab_contents()); - g_signal_connect(view->native_view(), "leave-notify-event", - G_CALLBACK(OnLeaveNotify2), tab_contents()); - g_signal_connect(view->native_view(), "motion-notify-event", - G_CALLBACK(CallMouseMove), this); - g_signal_connect(view->native_view(), "scroll-event", - G_CALLBACK(OnMouseScroll), tab_contents()); - gtk_widget_add_events(view->native_view(), GDK_LEAVE_NOTIFY_MASK | - GDK_POINTER_MOTION_MASK); - - // Let widget know that the tab contents has been painted. - views::WidgetGtk::RegisterChildExposeHandler(view->native_view()); - - // Renderer target DnD. - if (tab_contents()->ShouldAcceptDragAndDrop()) - drag_dest_.reset(new WebDragDestGtk(tab_contents(), view->native_view())); - - gtk_fixed_put(GTK_FIXED(GetNativeView()), view->native_view(), 0, 0); - return view; -} - -gfx::NativeView TabContentsViewGtk::GetNativeView() const { - return WidgetGtk::GetNativeView(); -} - -gfx::NativeView TabContentsViewGtk::GetContentNativeView() const { - RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); - if (!rwhv) - return NULL; - return rwhv->GetNativeView(); -} - -gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { - GtkWidget* window = gtk_widget_get_ancestor(GetNativeView(), GTK_TYPE_WINDOW); - return window ? GTK_WINDOW(window) : NULL; -} - -void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { - // Callers expect the requested bounds not the actual bounds. For example, - // during init callers expect 0x0, but Gtk layout enforces a min size of 1x1. - *out = GetClientAreaScreenBounds(); - - gfx::Size size; - WidgetGtk::GetRequestedSize(&size); - out->set_size(size); -} - -void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, - WebDragOperationsMask ops, - const SkBitmap& image, - const gfx::Point& image_offset) { - drag_source_->StartDragging(drop_data, ops, &last_mouse_down_, - image, image_offset); -} - -void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { - // Set the window name to include the page title so it's easier to spot - // when debugging (e.g. via xwininfo -tree). - gfx::NativeView content_view = GetContentNativeView(); - if (content_view && content_view->window) - gdk_window_set_title(content_view->window, WideToUTF8(title).c_str()); -} - -void TabContentsViewGtk::OnTabCrashed(base::TerminationStatus status, - int /* error_code */) { - SadTabView::Kind kind = - status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? - SadTabView::KILLED : SadTabView::CRASHED; - sad_tab_ = new SadTabView(tab_contents(), kind); - SetContentsView(sad_tab_); -} - -void TabContentsViewGtk::SizeContents(const gfx::Size& size) { - // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h. - - // We're contained in a fixed. To have the fixed relay us out to |size|, set - // the size request, which triggers OnSizeAllocate. - gtk_widget_set_size_request(GetNativeView(), size.width(), size.height()); - - // We need to send this immediately. - RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetSize(size); -} - -void TabContentsViewGtk::Focus() { - if (tab_contents()->interstitial_page()) { - tab_contents()->interstitial_page()->Focus(); - return; - } - - if (tab_contents()->is_crashed() && sad_tab_ != NULL) { - sad_tab_->RequestFocus(); - return; - } - - if (constrained_windows_.size()) { - constrained_windows_.back()->FocusConstrainedWindow(); - return; - } - - RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); - gtk_widget_grab_focus(rwhv ? rwhv->GetNativeView() : GetNativeView()); -} - -void TabContentsViewGtk::SetInitialFocus() { - if (tab_contents()->FocusLocationBarByDefault()) - tab_contents()->SetFocusToLocationBar(false); - else - Focus(); -} - -void TabContentsViewGtk::StoreFocus() { - views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); - - if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL) - view_storage->RemoveView(last_focused_view_storage_id_); - - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); - if (focus_manager) { - // |focus_manager| can be NULL if the tab has been detached but still - // exists. - views::View* focused_view = focus_manager->GetFocusedView(); - if (focused_view) - view_storage->StoreView(last_focused_view_storage_id_, focused_view); - } -} - -void TabContentsViewGtk::RestoreFocus() { - views::ViewStorage* view_storage = views::ViewStorage::GetInstance(); - views::View* last_focused_view = - view_storage->RetrieveView(last_focused_view_storage_id_); - if (!last_focused_view) { - SetInitialFocus(); - } else { - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); - - // If you hit this DCHECK, please report it to Jay (jcampan). - DCHECK(focus_manager != NULL) << "No focus manager when restoring focus."; - - if (last_focused_view->IsFocusableInRootView() && focus_manager && - focus_manager->ContainsView(last_focused_view)) { - last_focused_view->RequestFocus(); - } else { - // The focused view may not belong to the same window hierarchy (e.g. - // if the location bar was focused and the tab is dragged out), or it may - // no longer be focusable (e.g. if the location bar was focused and then - // we switched to fullscreen mode). In that case we default to the - // default focus. - SetInitialFocus(); - } - view_storage->RemoveView(last_focused_view_storage_id_); - } -} - -void TabContentsViewGtk::GetViewBounds(gfx::Rect* out) const { - *out = GetWindowScreenBounds(); -} - -void TabContentsViewGtk::UpdateDragCursor(WebDragOperation operation) { - if (drag_dest_.get()) - drag_dest_->UpdateDragStatus(operation); -} - -void TabContentsViewGtk::GotFocus() { - if (tab_contents()->delegate()) - tab_contents()->delegate()->TabContentsFocused(tab_contents()); -} - -void TabContentsViewGtk::TakeFocus(bool reverse) { - if (tab_contents()->delegate() && - !tab_contents()->delegate()->TakeFocus(reverse)) { - - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); - - // We may not have a focus manager if the tab has been switched before this - // message arrived. - if (focus_manager) - focus_manager->AdvanceFocus(reverse); - } -} - -void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { - // Allow delegates to handle the context menu operation first. - if (tab_contents()->delegate()->HandleContextMenu(params)) - return; - - context_menu_.reset(new RenderViewContextMenuViews(tab_contents(), params)); - context_menu_->Init(); - - gfx::Point screen_point(params.x, params.y); - views::View::ConvertPointToScreen(GetRootView(), &screen_point); - - // Enable recursive tasks on the message loop so we can get updates while - // the context menu is being displayed. - bool old_state = MessageLoop::current()->NestableTasksAllowed(); - MessageLoop::current()->SetNestableTasksAllowed(true); - context_menu_->RunMenuAt(screen_point.x(), screen_point.y()); - MessageLoop::current()->SetNestableTasksAllowed(old_state); -} - -void TabContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, - int item_height, - double item_font_size, - int selected_item, - const std::vector<WebMenuItem>& items, - bool right_aligned) { - // External popup menus are only used on Mac. - NOTREACHED(); -} - -gboolean TabContentsViewGtk::OnButtonPress(GtkWidget* widget, - GdkEventButton* event) { - last_mouse_down_ = *event; - return views::WidgetGtk::OnButtonPress(widget, event); -} - -void TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, - GtkAllocation* allocation) { - gfx::Size new_size(allocation->width, allocation->height); - - // Always call WasSized() to allow checking to make sure the - // RenderWidgetHostView is the right size. - WasSized(new_size); -} - -gboolean TabContentsViewGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) { - if (tab_contents()->render_view_host() && - !tab_contents()->render_view_host()->IsRenderViewLive() && - sad_tab_) { - gfx::CanvasSkiaPaint canvas(event); - sad_tab_->Paint(&canvas); - } - return false; // False indicates other widgets should get the event as well. -} - -void TabContentsViewGtk::OnShow(GtkWidget* widget) { - WasShown(); -} - -void TabContentsViewGtk::OnHide(GtkWidget* widget) { - WasHidden(); -} - -void TabContentsViewGtk::WasHidden() { - tab_contents()->HideContents(); -} - -void TabContentsViewGtk::WasShown() { - tab_contents()->ShowContents(); -} - -void TabContentsViewGtk::WasSized(const gfx::Size& size) { - // We have to check that the RenderWidgetHostView is the proper size. - // It can be wrong in cases where the renderer has died and the host - // view needed to be recreated. - bool needs_resize = size != size_; - - if (needs_resize) { - size_ = size; - if (tab_contents()->interstitial_page()) - tab_contents()->interstitial_page()->SetSize(size); - } - - RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); - if (rwhv && rwhv->GetViewBounds().size() != size) - rwhv->SetSize(size); - if (sad_tab_ && sad_tab_->size() != size) - sad_tab_->SetSize(size); - - if (needs_resize) - SetFloatingPosition(size); -} - -void TabContentsViewGtk::SetFloatingPosition(const gfx::Size& size) { - // Place each ConstrainedWindow in the center of the view. - int half_view_width = size.width() / 2; - - typedef std::vector<ConstrainedWindowGtk*>::iterator iterator; - - for (iterator f = constrained_windows_.begin(), - l = constrained_windows_.end(); f != l; ++f) { - GtkWidget* widget = (*f)->widget(); - - GtkRequisition requisition; - gtk_widget_size_request(widget, &requisition); - - int child_x = std::max(half_view_width - (requisition.width / 2), 0); - PositionChild(widget, child_x, 0, 0, 0); - } -} - -// Called when the mouse moves within the widget. We notify SadTabView if it's -// not NULL, else our delegate. -gboolean TabContentsViewGtk::OnMouseMove(GtkWidget* widget, - GdkEventMotion* event) { - if (sad_tab_ != NULL) - WidgetGtk::OnMotionNotify(widget, event); - else if (tab_contents()->delegate()) - tab_contents()->delegate()->ContentsMouseEvent( - tab_contents(), views::Screen::GetCursorScreenPoint(), true); - return FALSE; -} diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.h b/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.h deleted file mode 100644 index 0834a60..0000000 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_gtk.h +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_ -#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_ -#pragma once - -#include <vector> - -#include "base/memory/scoped_ptr.h" -#include "content/browser/tab_contents/tab_contents_view.h" -#include "ui/gfx/size.h" -#include "views/widget/widget_gtk.h" - -class ConstrainedWindowGtk; -typedef struct _GtkFloatingContainer GtkFloatingContainer; -class RenderViewContextMenuViews; -class SadTabView; -class SkBitmap; -class TabContentsDragSource; -class WebDragDestGtk; -namespace gfx { -class Point; -} -namespace views { -class NativeViewHost; -} - -// Gtk-specific implementation of the TabContentsView for the views-based front -// end. It is a WidgetGtk that contains all of the contents of the tab and -// associated child views. -class TabContentsViewGtk : public TabContentsView, - public views::WidgetGtk { - public: - // The corresponding TabContents is passed in the constructor, and manages our - // lifetime. This doesn't need to be the case, but is this way currently - // because that's what was easiest when they were split. - explicit TabContentsViewGtk(TabContents* tab_contents); - virtual ~TabContentsViewGtk(); - - // Unlike Windows, ConstrainedWindows need to collaborate with the - // TabContentsViewGtk to position the dialogs. - void AttachConstrainedWindow(ConstrainedWindowGtk* constrained_window); - void RemoveConstrainedWindow(ConstrainedWindowGtk* constrained_window); - - gboolean OnMouseMove(GtkWidget* widget, GdkEventMotion* event); - - // TabContentsView implementation -------------------------------------------- - - virtual void CreateView(const gfx::Size& initial_size); - virtual RenderWidgetHostView* CreateViewForWidget( - RenderWidgetHost* render_widget_host); - virtual gfx::NativeView GetNativeView() const; - virtual gfx::NativeView GetContentNativeView() const; - virtual gfx::NativeWindow GetTopLevelNativeWindow() const; - virtual void GetContainerBounds(gfx::Rect* out) const; - virtual void SetPageTitle(const std::wstring& title); - virtual void OnTabCrashed(base::TerminationStatus status, - int error_code); - virtual void SizeContents(const gfx::Size& size); - virtual void Focus(); - virtual void SetInitialFocus(); - virtual void StoreFocus(); - virtual void RestoreFocus(); - virtual void GetViewBounds(gfx::Rect* out) const; - - // Backend implementation of RenderViewHostDelegate::View. - virtual void ShowContextMenu(const ContextMenuParams& params); - virtual void ShowPopupMenu(const gfx::Rect& bounds, - int item_height, - double item_font_size, - int selected_item, - const std::vector<WebMenuItem>& items, - bool right_aligned); - virtual void StartDragging(const WebDropData& drop_data, - WebKit::WebDragOperationsMask ops_allowed, - const SkBitmap& image, - const gfx::Point& image_offset); - virtual void UpdateDragCursor(WebKit::WebDragOperation operation); - virtual void GotFocus(); - virtual void TakeFocus(bool reverse); - - private: - // Signal handlers ----------------------------------------------------------- - - // Overridden from views::WidgetGtk: - virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event); - virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); - virtual gboolean OnPaint(GtkWidget* widget, GdkEventExpose* event); - virtual void OnShow(GtkWidget* widget); - virtual void OnHide(GtkWidget* widget); - - // Handles notifying the TabContents and other operations when the window was - // shown or hidden. - void WasHidden(); - void WasShown(); - - // Handles resizing of the contents. This will notify the RenderWidgetHostView - // of the change, reposition popups, and the find in page bar. - void WasSized(const gfx::Size& size); - - // For any floating views (ConstrainedDialogs) this function centers them - // within this view. It's called whem a ConstrainedDialog is attached and - // when this view is resized. - void SetFloatingPosition(const gfx::Size& size); - - // --------------------------------------------------------------------------- - - // Used to render the sad tab. This will be non-NULL only when the sad tab is - // visible. - SadTabView* sad_tab_; - - // Whether to ignore the next CHAR keyboard event. - bool ignore_next_char_event_; - - // The id used in the ViewStorage to store the last focused view. - int last_focused_view_storage_id_; - - // The context menu. Callbacks are asynchronous so we need to keep it around. - scoped_ptr<RenderViewContextMenuViews> context_menu_; - - // Handles drags from this TabContentsView. - scoped_ptr<TabContentsDragSource> drag_source_; - - // The event for the last mouse down we handled. We need this for drags. - GdkEventButton last_mouse_down_; - - // The helper object that handles drag destination related interactions with - // GTK. - scoped_ptr<WebDragDestGtk> drag_dest_; - - // Current size. See comment in WidgetGtk as to why this is cached. - gfx::Size size_; - - // Each individual UI for constrained dialogs currently displayed. The - // objects in this vector are owned by the TabContents, not the view. - std::vector<ConstrainedWindowGtk*> constrained_windows_; - - DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_VIEW_GTK_H_ diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc index ab4f4c4..3d88f73 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc @@ -4,8 +4,6 @@ #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" -#include <windows.h> - #include <vector> #include "base/time.h" @@ -26,6 +24,10 @@ #include "views/widget/root_view.h" #include "views/widget/widget.h" +#if defined(OS_WIN) +#include <windows.h> +#endif + using WebKit::WebDragOperation; using WebKit::WebDragOperationNone; using WebKit::WebDragOperationsMask; @@ -38,10 +40,10 @@ TabContentsView* TabContentsView::Create(TabContents* tab_contents) { TabContentsViewViews::TabContentsViewViews(TabContents* tab_contents) : TabContentsView(tab_contents), - ALLOW_THIS_IN_INITIALIZER_LIST(native_tab_contents_view_( - NativeTabContentsView::CreateNativeTabContentsView(this))), + native_tab_contents_view_(NULL), + sad_tab_(NULL), close_tab_after_drag_ends_(false), - sad_tab_(NULL) { + focus_manager_(NULL) { last_focused_view_storage_id_ = views::ViewStorage::GetInstance()->CreateStorageID(); } @@ -57,11 +59,16 @@ TabContentsViewViews::~TabContentsViewViews() { } void TabContentsViewViews::Unparent() { - CHECK(native_tab_contents_view_.get()); + // Remember who our FocusManager is, we won't be able to access it once + // un-parented. + focus_manager_ = GetFocusManager(); + CHECK(native_tab_contents_view_); native_tab_contents_view_->Unparent(); } void TabContentsViewViews::CreateView(const gfx::Size& initial_size) { + native_tab_contents_view_ = + NativeTabContentsView::CreateNativeTabContentsView(this); native_tab_contents_view_->InitNativeTabContentsView(); } @@ -79,7 +86,7 @@ RenderWidgetHostView* TabContentsViewViews::CreateViewForWidget( // If we were showing sad tab, remove it now. if (sad_tab_) { - GetWidget()->SetContentsView(new views::View()); + SetContentsView(new views::View()); sad_tab_ = NULL; } @@ -88,7 +95,7 @@ RenderWidgetHostView* TabContentsViewViews::CreateViewForWidget( } gfx::NativeView TabContentsViewViews::GetNativeView() const { - return GetWidget()->GetNativeView(); + return Widget::GetNativeView(); } gfx::NativeView TabContentsViewViews::GetContentNativeView() const { @@ -97,11 +104,11 @@ gfx::NativeView TabContentsViewViews::GetContentNativeView() const { } gfx::NativeWindow TabContentsViewViews::GetTopLevelNativeWindow() const { - return native_tab_contents_view_->GetTopLevelNativeWindow(); + return GetTopLevelWidget()->GetNativeWindow(); } void TabContentsViewViews::GetContainerBounds(gfx::Rect* out) const { - *out = GetWidget()->GetClientAreaScreenBounds(); + *out = GetClientAreaScreenBounds(); } void TabContentsViewViews::StartDragging(const WebDropData& drop_data, @@ -119,18 +126,18 @@ void TabContentsViewViews::OnTabCrashed(base::TerminationStatus status, int /* error_code */) { // Force an invalidation to render sad tab. // Note that it's possible to get this message after the window was destroyed. - if (::IsWindow(GetNativeView())) { + if (GetNativeView()) { SadTabView::Kind kind = status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? SadTabView::KILLED : SadTabView::CRASHED; sad_tab_ = new SadTabView(tab_contents(), kind); - GetWidget()->SetContentsView(sad_tab_); + SetContentsView(sad_tab_); sad_tab_->SchedulePaint(); } } void TabContentsViewViews::SizeContents(const gfx::Size& size) { - GetWidget()->SetSize(size); + SetSize(size); } void TabContentsViewViews::Focus() { @@ -152,8 +159,8 @@ void TabContentsViewViews::Focus() { } RenderWidgetHostView* rwhv = tab_contents()->GetRenderWidgetHostView(); - GetWidget()->GetFocusManager()->FocusNativeView(rwhv ? rwhv->GetNativeView() - : GetNativeView()); + GetFocusManager()->FocusNativeView(rwhv ? rwhv->GetNativeView() + : GetNativeView()); } void TabContentsViewViews::SetInitialFocus() { @@ -223,7 +230,7 @@ void TabContentsViewViews::CancelDragAndCloseTab() { } void TabContentsViewViews::GetViewBounds(gfx::Rect* out) const { - *out = GetWidget()->GetWindowScreenBounds(); + *out = GetWindowScreenBounds(); } void TabContentsViewViews::UpdateDragCursor(WebDragOperation operation) { @@ -247,14 +254,6 @@ void TabContentsViewViews::TakeFocus(bool reverse) { } } -views::Widget* TabContentsViewViews::GetWidget() { - return native_tab_contents_view_->AsNativeWidget()->GetWidget(); -} - -const views::Widget* TabContentsViewViews::GetWidget() const { - return native_tab_contents_view_->AsNativeWidget()->GetWidget(); -} - void TabContentsViewViews::CloseTab() { tab_contents()->Close(tab_contents()->render_view_host()); } @@ -267,14 +266,14 @@ void TabContentsViewViews::ShowContextMenu(const ContextMenuParams& params) { context_menu_.reset(new RenderViewContextMenuViews(tab_contents(), params)); context_menu_->Init(); - POINT screen_pt = { params.x, params.y }; - MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); + gfx::Point screen_point(params.x, params.y); + views::View::ConvertPointToScreen(GetRootView(), &screen_point); // Enable recursive tasks on the message loop so we can get updates while // the context menu is being displayed. bool old_state = MessageLoop::current()->NestableTasksAllowed(); MessageLoop::current()->SetNestableTasksAllowed(true); - context_menu_->RunMenuAt(screen_pt.x, screen_pt.y); + context_menu_->RunMenuAt(screen_point.x(), screen_point.y()); MessageLoop::current()->SetNestableTasksAllowed(old_state); } @@ -315,11 +314,9 @@ void TabContentsViewViews::OnNativeTabContentsViewSized(const gfx::Size& size) { rwhv->SetSize(size); } -void TabContentsViewViews::OnNativeTabContentsViewWheelZoom(int distance) { - if (tab_contents()->delegate()) { - bool zoom_in = distance > 0; +void TabContentsViewViews::OnNativeTabContentsViewWheelZoom(bool zoom_in) { + if (tab_contents()->delegate()) tab_contents()->delegate()->ContentsZoomChange(zoom_in); - } } void TabContentsViewViews::OnNativeTabContentsViewMouseDown() { @@ -328,12 +325,12 @@ void TabContentsViewViews::OnNativeTabContentsViewMouseDown() { tab_contents()->delegate()->ActivateContents(tab_contents()); } -void TabContentsViewViews::OnNativeTabContentsViewMouseMove() { +void TabContentsViewViews::OnNativeTabContentsViewMouseMove(bool motion) { // Let our delegate know that the mouse moved (useful for resetting status // bubble state). if (tab_contents()->delegate()) { tab_contents()->delegate()->ContentsMouseEvent( - tab_contents(), views::Screen::GetCursorScreenPoint(), true); + tab_contents(), views::Screen::GetCursorScreenPoint(), motion); } } @@ -344,3 +341,28 @@ void TabContentsViewViews::OnNativeTabContentsViewDraggingEnded() { } tab_contents()->SystemDragEnded(); } + +views::internal::NativeWidgetDelegate* + TabContentsViewViews::AsNativeWidgetDelegate() { + return this; +} + +//////////////////////////////////////////////////////////////////////////////// +// TabContentsViewViews, views::Widget overrides: + +views::FocusManager* TabContentsViewViews::GetFocusManager() { + views::FocusManager* focus_manager = Widget::GetFocusManager(); + if (focus_manager) { + // If focus_manager_ is non NULL, it means we have been reparented, in which + // case its value may not be valid anymore. + focus_manager_ = NULL; + return focus_manager; + } + // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be + // NULL. We are not doing it as it breaks some unit-tests. We should + // probably have an empty TabContentView implementation for the unit-tests, + // that would prevent that code being executed in the unit-test case. + // DCHECK(focus_manager_); + return focus_manager_; +} + diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h index bc7b622..0bd78ff 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h +++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.h @@ -10,6 +10,7 @@ #include "base/timer.h" #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" #include "content/browser/tab_contents/tab_contents_view.h" +#include "views/widget/widget.h" class NativeTabContentsView; class RenderViewContextMenuViews; @@ -27,7 +28,8 @@ class Widget; // Views-specific implementation of the TabContentsView. // TODO(beng): Remove last remnants of Windows-specificity, and make this // subclass Widget. -class TabContentsViewViews : public TabContentsView, +class TabContentsViewViews : public views::Widget, + public TabContentsView, public internal::NativeTabContentsViewDelegate { public: // The corresponding TabContents is passed in the constructor, and manages our @@ -40,6 +42,10 @@ class TabContentsViewViews : public TabContentsView, // not receive any messages. virtual void Unparent(); + NativeTabContentsView* native_tab_contents_view() const { + return native_tab_contents_view_; + } + // Overridden from TabContentsView: virtual void CreateView(const gfx::Size& initial_size) OVERRIDE; virtual RenderWidgetHostView* CreateViewForWidget( @@ -81,13 +87,15 @@ class TabContentsViewViews : public TabContentsView, virtual void OnNativeTabContentsViewShown() OVERRIDE; virtual void OnNativeTabContentsViewHidden() OVERRIDE; virtual void OnNativeTabContentsViewSized(const gfx::Size& size) OVERRIDE; - virtual void OnNativeTabContentsViewWheelZoom(int distance) OVERRIDE; + virtual void OnNativeTabContentsViewWheelZoom(bool zoom_in) OVERRIDE; virtual void OnNativeTabContentsViewMouseDown() OVERRIDE; - virtual void OnNativeTabContentsViewMouseMove() OVERRIDE; + virtual void OnNativeTabContentsViewMouseMove(bool motion) OVERRIDE; virtual void OnNativeTabContentsViewDraggingEnded() OVERRIDE; + virtual views::internal::NativeWidgetDelegate* AsNativeWidgetDelegate() + OVERRIDE; - views::Widget* GetWidget(); - const views::Widget* GetWidget() const; + // Overridden from views::Widget: + virtual views::FocusManager* GetFocusManager() OVERRIDE; // A helper method for closing the tab. void CloseTab(); @@ -108,7 +116,7 @@ class TabContentsViewViews : public TabContentsView, // --------------------------------------------------------------------------- - scoped_ptr<NativeTabContentsView> native_tab_contents_view_; + NativeTabContentsView* native_tab_contents_view_; // Used to render the sad tab. This will be non-NULL only when the sad tab is // visible. @@ -127,6 +135,10 @@ class TabContentsViewViews : public TabContentsView, // Used to close the tab after the stack has unwound. base::OneShotTimer<TabContentsViewViews> close_tab_timer_; + // The FocusManager associated with this tab. Stored as it is not directly + // accessible when un-parented. + views::FocusManager* focus_manager_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewViews); }; diff --git a/chrome/browser/ui/views/tabs/base_tab_strip.cc b/chrome/browser/ui/views/tabs/base_tab_strip.cc index 8178edd..ad3df63 100644 --- a/chrome/browser/ui/views/tabs/base_tab_strip.cc +++ b/chrome/browser/ui/views/tabs/base_tab_strip.cc @@ -94,15 +94,14 @@ class BaseTabStrip::RemoveTabDelegate // This can be null during shutdown. See http://crbug.com/42737. if (!widget) return; + + widget->ResetLastMouseMoveFlag(); + // Force the close button (that slides under the mouse) to highlight by // saying the mouse just moved, but sending the same coordinates. DWORD pos = GetMessagePos(); POINT cursor_point = {GET_X_LPARAM(pos), GET_Y_LPARAM(pos)}; MapWindowPoints(NULL, widget->GetNativeView(), &cursor_point, 1); - - static_cast<views::WidgetWin*>(widget)->ResetLastMouseMoveFlag(); - // Return to message loop - otherwise we may disrupt some operation that's - // in progress. SendMessage(widget->GetNativeView(), WM_MOUSEMOVE, 0, MAKELPARAM(cursor_point.x, cursor_point.y)); #else diff --git a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc index cb0965c..0045a8b 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_controller.cc @@ -203,8 +203,7 @@ class DraggedTabController::DockDisplayer : public ui::AnimationDelegate { hidden_(false), in_enable_area_(info.in_enable_area()) { #if defined(OS_WIN) - popup_ = views::Widget::CreateWidget(); - popup_->SetOpacity(0x00); + popup_ = new views::Widget; // TODO(sky): This should "just work" on Gtk now. views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; @@ -212,6 +211,7 @@ class DraggedTabController::DockDisplayer : public ui::AnimationDelegate { params.bounds = info.GetPopupRect(); popup_->Init(params); popup_->SetContentsView(new DockView(info.type())); + popup_->SetOpacity(0x00); if (info.in_enable_area()) animation_.Reset(1); else @@ -265,23 +265,15 @@ class DraggedTabController::DockDisplayer : public ui::AnimationDelegate { virtual void AnimationEnded(const ui::Animation* animation) { if (!hidden_) return; -#if defined(OS_WIN) - static_cast<views::WidgetWin*>(popup_)->Close(); -#else - NOTIMPLEMENTED(); -#endif + popup_->Close(); delete this; } virtual void UpdateLayeredAlpha() { -#if defined(OS_WIN) double scale = in_enable_area_ ? 1 : .5; - static_cast<views::WidgetWin*>(popup_)->SetOpacity( - static_cast<BYTE>(animation_.GetCurrentValue() * scale * 255.0)); + popup_->SetOpacity(static_cast<unsigned char>(animation_.GetCurrentValue() * + scale * 255.0)); popup_->GetRootView()->SchedulePaint(); -#else - NOTIMPLEMENTED(); -#endif } private: diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index b099339..ce763ba 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -39,9 +39,16 @@ DraggedTabView::DraggedTabView(const std::vector<views::View*>& renderers, contents_size_(contents_size) { set_parent_owned(false); - container_.reset(views::Widget::CreateWidget()); + container_.reset(new views::Widget); + views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); + params.transparent = true; + params.keep_on_top = true; + params.delete_on_destroy = false; + params.bounds = gfx::Rect(PreferredContainerSize()); + container_->Init(params); + container_->SetContentsView(this); #if defined(OS_WIN) - static_cast<views::WidgetWin*>(container_.get())-> + static_cast<views::WidgetWin*>(container_->native_widget())-> set_can_update_layered_window(false); BOOL drag; @@ -50,13 +57,6 @@ DraggedTabView::DraggedTabView(const std::vector<views::View*>& renderers, show_contents_on_drag_ = false; } #endif - views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); - params.transparent = true; - params.keep_on_top = true; - params.delete_on_destroy = false; - params.bounds = gfx::Rect(PreferredContainerSize()); - container_->Init(params); - container_->SetContentsView(this); container_->SetOpacity(kTransparentAlpha); container_->SetBounds(gfx::Rect(gfx::Point(), params.bounds.size())); } diff --git a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc index a010e3d..4bfd3609 100644 --- a/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc +++ b/chrome/browser/ui/views/tabs/native_view_photobooth_win.cc @@ -151,7 +151,7 @@ void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { gfx::Rect capture_bounds(window_position.x(), window_position.y(), contents_rect.right - contents_rect.left, contents_rect.bottom - contents_rect.top); - capture_window_ = views::Widget::CreateWidget(); + capture_window_ = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.bounds = capture_bounds; diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc index bafe9a1..e3f62d2 100644 --- a/chrome/browser/ui/views/tabs/tab.cc +++ b/chrome/browser/ui/views/tabs/tab.cc @@ -450,7 +450,7 @@ void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas) { int tab_id; if (GetWidget() && - GetWidget()->GetWindow()->non_client_view()->UseNativeFrame()) { + GetWidget()->GetContainingWindow()->non_client_view()->UseNativeFrame()) { tab_id = IDR_THEME_TAB_BACKGROUND_V; } else { tab_id = data().incognito ? IDR_THEME_TAB_BACKGROUND_INCOGNITO : diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 45c9545..15790fa 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -860,7 +860,7 @@ TabStrip::DropInfo::DropInfo(int drop_index, bool drop_before, bool point_down) arrow_view = new views::ImageView; arrow_view->SetImage(GetDropArrowImage(point_down)); - arrow_window = views::Widget::CreateWidget(); + arrow_window = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.keep_on_top = true; params.transparent = true; diff --git a/chrome/browser/ui/views/task_manager_view.cc b/chrome/browser/ui/views/task_manager_view.cc index eef260f..93ee630 100644 --- a/chrome/browser/ui/views/task_manager_view.cc +++ b/chrome/browser/ui/views/task_manager_view.cc @@ -561,7 +561,7 @@ void TaskManagerView::Show(bool highlight_background_resources) { if (instance_) { if (instance_->highlight_background_resources_ != highlight_background_resources) { - instance_->window()->CloseWindow(); + instance_->window()->Close(); } else { // If there's a Task manager window open already, just activate it. instance_->window()->Activate(); diff --git a/chrome/browser/ui/views/theme_install_bubble_view.cc b/chrome/browser/ui/views/theme_install_bubble_view.cc index 9f35eff..b099af95 100644 --- a/chrome/browser/ui/views/theme_install_bubble_view.cc +++ b/chrome/browser/ui/views/theme_install_bubble_view.cc @@ -70,14 +70,14 @@ ThemeInstallBubbleView::ThemeInstallBubbleView(TabContents* tab_contents) NotificationType::EXTENSION_WILL_SHOW_CONFIRM_DIALOG, NotificationService::AllSources()); - popup_ = views::Widget::CreateWidget(); - popup_->SetOpacity(0xCC); + popup_ = new views::Widget; views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.transparent = true; params.accept_events = false; params.parent = tab_contents->GetNativeView(); popup_->Init(params); popup_->SetContentsView(this); + popup_->SetOpacity(0xCC); Reposition(); popup_->Show(); |