summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-19 22:57:54 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-19 22:57:54 +0000
commita109d02492863aeb537dea09bfb445eb6f5d94c5 (patch)
treebd3d2e9a783179eb2582f0055192b97e8d248547
parent3c30f4c1e5f2bdb4f5d198c4a9ea18cc8045ddea (diff)
downloadchromium_src-a109d02492863aeb537dea09bfb445eb6f5d94c5.zip
chromium_src-a109d02492863aeb537dea09bfb445eb6f5d94c5.tar.gz
chromium_src-a109d02492863aeb537dea09bfb445eb6f5d94c5.tar.bz2
Removed the last Windows specific part out of the focus manager. HWNDs are not subclassed anymore.The FocusManager is now created and owned by top-level WidgetWins.BUG=NoneTEST=Run the unit tests, UI tests, interactive UI tests. Fully test the focus behavior in the browser: activate/deactivate the browser windows, make sure focus is remembered. Switch tabs, make sure focus is remembered for each tab. make sure accelerators work as expected. Test focus traversal in a web page, in the option dialog.
Review URL: http://codereview.chromium.org/125148 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18872 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc3
-rwxr-xr-xchrome/browser/automation/automation_provider.cc2
-rw-r--r--chrome/browser/browser_focus_uitest.cc22
-rw-r--r--chrome/browser/external_tab_container.cc3
-rw-r--r--chrome/browser/first_run_win.cc2
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_win.cc2
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_win.cc4
-rw-r--r--chrome/browser/views/blocked_popup_container_view_win.cc2
-rw-r--r--chrome/browser/views/bookmark_bubble_view.cc4
-rw-r--r--chrome/browser/views/browser_bubble_win.cc4
-rw-r--r--chrome/browser/views/constrained_window_impl.cc691
-rw-r--r--chrome/browser/views/download_started_animation_win.cc2
-rw-r--r--chrome/browser/views/find_bar_win.cc5
-rw-r--r--chrome/browser/views/find_bar_win_browsertest.cc5
-rw-r--r--chrome/browser/views/first_run_bubble.cc8
-rw-r--r--chrome/browser/views/fullscreen_exit_bubble.cc2
-rw-r--r--chrome/browser/views/info_bubble.cc10
-rw-r--r--chrome/browser/views/infobars/infobars.cc5
-rw-r--r--chrome/browser/views/shelf_item_dialog.cc3
-rw-r--r--chrome/browser/views/status_bubble_views.cc2
-rwxr-xr-xchrome/browser/views/tab_contents/tab_contents_view_win.cc12
-rw-r--r--chrome/browser/views/tabs/dragged_tab_controller.cc2
-rw-r--r--chrome/browser/views/tabs/dragged_tab_view.cc2
-rw-r--r--chrome/browser/views/tabs/native_view_photobooth_win.cc2
-rw-r--r--chrome/browser/views/tabs/tab_strip.cc3
-rw-r--r--views/controls/menu/chrome_menu.cc2
-rw-r--r--views/controls/native_control.cc3
-rw-r--r--views/controls/native_control_win.cc3
-rw-r--r--views/controls/tabbed_pane.cc2
-rw-r--r--views/controls/textfield/native_textfield_win.cc3
-rwxr-xr-xviews/controls/tree/tree_view.cc4
-rw-r--r--views/focus/external_focus_tracker.cc3
-rw-r--r--views/focus/focus_manager.cc224
-rw-r--r--views/focus/focus_manager.h85
-rw-r--r--views/focus/focus_manager_gtk.cc25
-rw-r--r--views/focus/focus_manager_unittest.cc5
-rw-r--r--views/focus/focus_manager_win.cc33
-rw-r--r--views/view.cc5
-rw-r--r--views/view_unittest.cc10
-rw-r--r--views/view_win.cc14
-rw-r--r--views/views.gyp8
-rw-r--r--views/widget/accelerator_handler.cc3
-rw-r--r--views/widget/root_view.cc21
-rw-r--r--views/widget/widget.h9
-rw-r--r--views/widget/widget_win.cc41
-rw-r--r--views/widget/widget_win.h17
-rwxr-xr-xviews/window/window_win.cc2
47 files changed, 911 insertions, 413 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 03e7824..ed4237b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -1610,8 +1610,7 @@ void AutocompleteEditViewWin::OnPaste() {
}
void AutocompleteEditViewWin::OnSetFocus(HWND focus_wnd) {
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(m_hWnd);
+ views::FocusManager* focus_manager = parent_view_->GetFocusManager();
if (focus_manager) {
// Notify the FocusManager that the focused view is now the location bar
// (our parent view).
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index bcfd7a5..8432fee 100755
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -1729,7 +1729,7 @@ void AutomationProvider::GetFocusedViewID(int handle, int* view_id) {
if (window_tracker_->ContainsHandle(handle)) {
HWND hwnd = window_tracker_->GetResource(handle);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
DCHECK(focus_manager);
views::View* focused_view = focus_manager->GetFocusedView();
if (focused_view)
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index 3681c1b..8aebfcf 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -108,7 +108,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) {
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
ASSERT_TRUE(browser_view);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
ASSERT_TRUE(focus_manager);
EXPECT_EQ(browser_view->GetTabContentsContainerView(),
@@ -149,7 +149,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) {
BrowserView::GetBrowserViewForNativeWindow(hwnd2);
ASSERT_TRUE(browser_view2);
views::FocusManager* focus_manager2 =
- views::FocusManager::GetFocusManager(hwnd2);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd2);
ASSERT_TRUE(focus_manager2);
EXPECT_EQ(browser_view2->GetTabContentsContainerView(),
focus_manager2->GetFocusedView());
@@ -183,13 +183,13 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) {
ASSERT_TRUE(browser_view);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
ASSERT_TRUE(focus_manager);
// Create several tabs.
for (int i = 0; i < 4; ++i) {
- browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, false,
- NULL);
+ browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1,
+ false, NULL);
}
// Alternate focus for the tab.
@@ -283,7 +283,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) {
HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
// Click on the location bar.
LocationBarView* location_bar = browser_view->GetLocationBarView();
@@ -311,7 +311,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) {
HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
// Click on the location bar.
LocationBarView* location_bar = browser_view->GetLocationBarView();
@@ -401,7 +401,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversalOnInterstitial) {
HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
// Focus should be on the page.
EXPECT_EQ(browser_view->GetTabContentsContainerView(),
@@ -496,7 +496,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
// Page should have focus.
EXPECT_EQ(browser_view->GetTabContentsContainerView(),
@@ -541,7 +541,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle());
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
LocationBarView* location_bar = browser_view->GetLocationBarView();
// Press Ctrl+F, which will make the Find box open and request focus.
@@ -613,7 +613,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabInitialFocus) {
BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd);
ASSERT_TRUE(browser_view);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(hwnd);
+ views::FocusManager::GetFocusManagerForNativeView(hwnd);
ASSERT_TRUE(focus_manager);
// Open the history tab, focus should be on the tab contents.
diff --git a/chrome/browser/external_tab_container.cc b/chrome/browser/external_tab_container.cc
index 7da0be0..d7e4836 100644
--- a/chrome/browser/external_tab_container.cc
+++ b/chrome/browser/external_tab_container.cc
@@ -53,11 +53,12 @@ bool ExternalTabContainer::Init(Profile* profile,
}
set_window_style(WS_POPUP);
- views::WidgetWin::Init(NULL, bounds, true);
+ views::WidgetWin::Init(NULL, bounds);
if (!IsWindow()) {
NOTREACHED();
return false;
}
+ // TODO(jcampan): limit focus traversal to contents.
// We don't ever remove the prop because the lifetime of this object
// is the same as the lifetime of the window
diff --git a/chrome/browser/first_run_win.cc b/chrome/browser/first_run_win.cc
index 136350c..6f1d4a5 100644
--- a/chrome/browser/first_run_win.cc
+++ b/chrome/browser/first_run_win.cc
@@ -684,7 +684,7 @@ class TryChromeDialog : public views::ButtonListener,
popup->set_delete_on_destroy(true);
popup->set_window_style(WS_POPUP | WS_CLIPCHILDREN);
popup->set_window_ex_style(WS_EX_TOOLWINDOW);
- popup->Init(NULL, pos, true);
+ popup->Init(NULL, pos);
views::RootView* root_view = popup->GetRootView();
// The window color is a tiny bit off-white.
diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc
index e5091d6..5a75f50 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_win.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc
@@ -406,7 +406,7 @@ void RenderWidgetHostViewWin::Focus() {
void RenderWidgetHostViewWin::Blur() {
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetParent());
+ views::FocusManager::GetFocusManagerForNativeView(m_hWnd);
// We don't have a FocusManager if we are hidden.
if (focus_manager && render_widget_host_->CanBlur())
focus_manager->ClearFocus();
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
index 02d3118..accdbd5 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc
@@ -28,7 +28,9 @@ void AutocompletePopupWin::Init(AutocompleteEditViewWin* edit_view,
views::View* contents) {
// Create the popup
WidgetWin::Init(edit_view->parent_view()->GetWidget()->GetNativeView(),
- contents_->GetPopupBounds(), false);
+ contents_->GetPopupBounds());
+ // The contents is owned by the AutocompleteEditViewWin.
+ contents_->SetParentOwned(false);
// The contents is owned by the LocationBarView.
contents_->SetParentOwned(false);
SetContentsView(contents_);
diff --git a/chrome/browser/views/blocked_popup_container_view_win.cc b/chrome/browser/views/blocked_popup_container_view_win.cc
index 8e2837e..29240de 100644
--- a/chrome/browser/views/blocked_popup_container_view_win.cc
+++ b/chrome/browser/views/blocked_popup_container_view_win.cc
@@ -398,7 +398,7 @@ BlockedPopupContainerViewWin::BlockedPopupContainerViewWin(
set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
WidgetWin::Init(GetModel()->GetConstrainingContents(NULL)->GetNativeView(),
- gfx::Rect(), false);
+ gfx::Rect());
SetContentsView(container_view_);
SetPosition();
}
diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc
index 9a2a8f6..b81d0ab 100644
--- a/chrome/browser/views/bookmark_bubble_view.cc
+++ b/chrome/browser/views/bookmark_bubble_view.cc
@@ -182,9 +182,7 @@ void BookmarkBubbleView::DidChangeBounds(const gfx::Rect& previous,
void BookmarkBubbleView::BubbleShown() {
DCHECK(GetWidget());
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetWidget()->GetNativeView());
- focus_manager->RegisterAccelerator(
+ GetFocusManager()->RegisterAccelerator(
views::Accelerator(VK_RETURN, false, false, false), this);
title_tf_->RequestFocus();
diff --git a/chrome/browser/views/browser_bubble_win.cc b/chrome/browser/views/browser_bubble_win.cc
index 7b47fe9..e72545b 100644
--- a/chrome/browser/views/browser_bubble_win.cc
+++ b/chrome/browser/views/browser_bubble_win.cc
@@ -24,9 +24,7 @@ void BrowserBubble::InitPopup() {
#endif
// A focus manager is necessary if you want to be able to handle various
// mouse events properly.
- pop->Init(frame_native_view_,
- bounds_,
- true); // Give the widget a focus manager.
+ pop->Init(frame_native_view_, bounds_);
pop->SetContentsView(view_);
popup_.reset(pop);
Reposition();
diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc
new file mode 100644
index 0000000..39d3bcb
--- /dev/null
+++ b/chrome/browser/views/constrained_window_impl.cc
@@ -0,0 +1,691 @@
+// Copyright (c) 2006-2008 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/views/constrained_window_impl.h"
+
+#include "app/gfx/canvas.h"
+#include "app/gfx/font.h"
+#include "app/gfx/path.h"
+#include "app/gfx/text_elider.h"
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "app/win_util.h"
+#include "base/gfx/rect.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/browser/toolbar_model.h"
+#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/window_sizer.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+#include "grit/app_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "net/base/net_util.h"
+#include "views/controls/button/image_button.h"
+#include "views/focus/focus_manager.h"
+#include "views/window/client_view.h"
+#include "views/window/non_client_view.h"
+#include "views/window/window_resources.h"
+
+using base::TimeDelta;
+
+namespace views {
+class ClientView;
+}
+
+// An enumeration of bitmap resources used by this window.
+enum {
+ FRAME_PART_BITMAP_FIRST = 0, // Must be first.
+
+ // Window Controls.
+ FRAME_CLOSE_BUTTON_ICON,
+ FRAME_CLOSE_BUTTON_ICON_H,
+ FRAME_CLOSE_BUTTON_ICON_P,
+
+ // Window Frame Border.
+ FRAME_BOTTOM_EDGE,
+ FRAME_BOTTOM_LEFT_CORNER,
+ FRAME_BOTTOM_RIGHT_CORNER,
+ FRAME_LEFT_EDGE,
+ FRAME_RIGHT_EDGE,
+ FRAME_TOP_EDGE,
+ FRAME_TOP_LEFT_CORNER,
+ FRAME_TOP_RIGHT_CORNER,
+
+ FRAME_WINDOW,
+ FRAME_WINDOW_INACTIVE,
+ FRAME_WINDOW_INCOGNITO,
+ FRAME_WINDOW_INCOGNITO_INACTIVE,
+
+ FRAME_PART_BITMAP_COUNT // Must be last.
+};
+
+static const int kXPFramePartIDs[] = {
+ 0,
+ IDR_CLOSE_SA, IDR_CLOSE_SA_H, IDR_CLOSE_SA_P,
+ IDR_WINDOW_BOTTOM_CENTER, IDR_WINDOW_BOTTOM_LEFT_CORNER,
+ IDR_WINDOW_BOTTOM_RIGHT_CORNER, IDR_WINDOW_LEFT_SIDE,
+ IDR_WINDOW_RIGHT_SIDE, IDR_WINDOW_TOP_CENTER,
+ IDR_WINDOW_TOP_LEFT_CORNER, IDR_WINDOW_TOP_RIGHT_CORNER,
+ IDR_THEME_FRAME, IDR_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INCOGNITO,
+ IDR_THEME_FRAME_INCOGNITO_INACTIVE,
+ 0 };
+static const int kVistaFramePartIDs[] = {
+ 0,
+ IDR_CLOSE_SA, IDR_CLOSE_SA_H, IDR_CLOSE_SA_P,
+ IDR_CONSTRAINED_BOTTOM_CENTER_V, IDR_CONSTRAINED_BOTTOM_LEFT_CORNER_V,
+ IDR_CONSTRAINED_BOTTOM_RIGHT_CORNER_V, IDR_CONSTRAINED_LEFT_SIDE_V,
+ IDR_CONSTRAINED_RIGHT_SIDE_V, IDR_CONSTRAINED_TOP_CENTER_V,
+ IDR_CONSTRAINED_TOP_LEFT_CORNER_V, IDR_CONSTRAINED_TOP_RIGHT_CORNER_V,
+ IDR_THEME_FRAME, IDR_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INCOGNITO,
+ IDR_THEME_FRAME_INCOGNITO_INACTIVE,
+ 0 };
+
+class XPWindowResources : public views::WindowResources {
+ public:
+ XPWindowResources() {
+ InitClass();
+ }
+ virtual ~XPWindowResources() {}
+
+ virtual SkBitmap* GetPartBitmap(views::FramePartBitmap part_id) const {
+ return bitmaps_[part_id];
+ }
+
+ private:
+ static void InitClass() {
+ static bool initialized = false;
+ if (!initialized) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ for (int i = 0; i < FRAME_PART_BITMAP_COUNT; ++i) {
+ int id = kXPFramePartIDs[i];
+ if (id != 0)
+ bitmaps_[i] = rb.GetBitmapNamed(id);
+ }
+ initialized = true;
+ }
+ }
+
+ static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
+
+ DISALLOW_EVIL_CONSTRUCTORS(XPWindowResources);
+};
+
+class VistaWindowResources : public views::WindowResources {
+ public:
+ VistaWindowResources() {
+ InitClass();
+ }
+ virtual ~VistaWindowResources() {}
+
+ virtual SkBitmap* GetPartBitmap(views::FramePartBitmap part_id) const {
+ return bitmaps_[part_id];
+ }
+
+ private:
+ static void InitClass() {
+ static bool initialized = false;
+ if (!initialized) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ for (int i = 0; i < FRAME_PART_BITMAP_COUNT; ++i) {
+ int id = kVistaFramePartIDs[i];
+ if (id != 0)
+ bitmaps_[i] = rb.GetBitmapNamed(id);
+ }
+ initialized = true;
+ }
+ }
+
+ static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
+
+ DISALLOW_EVIL_CONSTRUCTORS(VistaWindowResources);
+};
+
+SkBitmap* XPWindowResources::bitmaps_[];
+SkBitmap* VistaWindowResources::bitmaps_[];
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView
+
+class ConstrainedWindowFrameView
+ : public views::NonClientFrameView,
+ public views::ButtonListener {
+ public:
+ explicit ConstrainedWindowFrameView(ConstrainedWindowImpl* container);
+ virtual ~ConstrainedWindowFrameView();
+
+ void UpdateWindowTitle();
+
+ // Overridden from views::NonClientFrameView:
+ virtual gfx::Rect GetBoundsForClientView() const;
+ virtual bool AlwaysUseCustomFrame() const;
+ virtual gfx::Rect GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const;
+ virtual gfx::Point GetSystemMenuPoint() const;
+ virtual int NonClientHitTest(const gfx::Point& point);
+ virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
+ virtual void EnableClose(bool enable);
+ virtual void ResetWindowControls() { }
+
+ // Overridden from views::View:
+ virtual void Paint(gfx::Canvas* canvas);
+ virtual void Layout();
+ virtual void ThemeChanged();
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
+
+ private:
+ // Returns the thickness of the border that makes up the window frame edges.
+ // This does not include any client edge.
+ int FrameBorderThickness() const;
+
+ // Returns the thickness of the entire nonclient left, right, and bottom
+ // borders, including both the window frame and any client edge.
+ int NonClientBorderThickness() const;
+
+ // Returns the height of the entire nonclient top border, including the window
+ // frame, any title area, and any connected client edge.
+ int NonClientTopBorderHeight() const;
+
+ // Calculates multiple values related to title layout. Returns the height of
+ // the entire titlebar including any connected client edge.
+ int TitleCoordinates(int* title_top_spacing,
+ int* title_thickness) const;
+
+ // Paints different parts of the window to the incoming canvas.
+ void PaintFrameBorder(gfx::Canvas* canvas);
+ void PaintTitleBar(gfx::Canvas* canvas);
+ void PaintClientEdge(gfx::Canvas* canvas);
+
+ // Layout various sub-components of this view.
+ void LayoutWindowControls();
+ void LayoutTitleBar();
+ void LayoutClientView();
+
+ // Returns the bounds of the client area for the specified view size.
+ gfx::Rect CalculateClientAreaBounds(int width, int height) const;
+
+ SkColor GetTitleColor() const {
+ return (container_->owner()->profile()->IsOffTheRecord() ||
+ !win_util::ShouldUseVistaFrame()) ? SK_ColorWHITE : SK_ColorBLACK;
+ }
+
+ // Loads the appropriate set of WindowResources for the frame view.
+ void InitWindowResources();
+
+ ConstrainedWindowImpl* container_;
+
+ scoped_ptr<views::WindowResources> resources_;
+
+ gfx::Rect title_bounds_;
+
+ views::ImageButton* close_button_;
+
+ // The bounds of the ClientView.
+ gfx::Rect client_view_bounds_;
+
+ static void InitClass();
+
+ // The font to be used to render the titlebar text.
+ static gfx::Font* title_font_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(ConstrainedWindowFrameView);
+};
+
+gfx::Font* ConstrainedWindowFrameView::title_font_ = NULL;
+
+namespace {
+// The frame border is only visible in restored mode and is hardcoded to 4 px on
+// each side regardless of the system window border size.
+const int kFrameBorderThickness = 4;
+// Various edges of the frame border have a 1 px shadow along their edges; in a
+// few cases we shift elements based on this amount for visual appeal.
+const int kFrameShadowThickness = 1;
+// In the window corners, the resize areas don't actually expand bigger, but the
+// 16 px at the end of each edge triggers diagonal resizing.
+const int kResizeAreaCornerSize = 16;
+// The titlebar never shrinks to less than 20 px tall, including the height of
+// the frame border and client edge.
+const int kTitlebarMinimumHeight = 20;
+// The icon is inset 2 px from the left frame border.
+const int kIconLeftSpacing = 2;
+// The title text starts 2 px below the bottom of the top frame border.
+const int kTitleTopSpacing = 2;
+// There is a 5 px gap between the title text and the caption buttons.
+const int kTitleCaptionSpacing = 5;
+// The caption buttons are always drawn 1 px down from the visible top of the
+// window (the true top in restored mode, or the top of the screen in maximized
+// mode).
+const int kCaptionTopSpacing = 1;
+
+const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView, public:
+
+ConstrainedWindowFrameView::ConstrainedWindowFrameView(
+ ConstrainedWindowImpl* container)
+ : NonClientFrameView(),
+ container_(container),
+ close_button_(new views::ImageButton(this)) {
+ InitClass();
+ InitWindowResources();
+
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
+ resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON));
+ close_button_->SetImage(views::CustomButton::BS_HOT,
+ resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H));
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
+ resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P));
+ close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
+ views::ImageButton::ALIGN_MIDDLE);
+ AddChildView(close_button_);
+}
+
+ConstrainedWindowFrameView::~ConstrainedWindowFrameView() {
+}
+
+void ConstrainedWindowFrameView::UpdateWindowTitle() {
+ SchedulePaint(title_bounds_, false);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView, views::NonClientFrameView implementation:
+
+gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const {
+ return client_view_bounds_;
+}
+
+bool ConstrainedWindowFrameView::AlwaysUseCustomFrame() const {
+ // Constrained windows always use the custom frame - they just have a
+ // different set of bitmaps.
+ return true;
+}
+
+gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const {
+ int top_height = NonClientTopBorderHeight();
+ int border_thickness = NonClientBorderThickness();
+ return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
+ std::max(0, client_bounds.y() - top_height),
+ client_bounds.width() + (2 * border_thickness),
+ client_bounds.height() + top_height + border_thickness);
+}
+
+gfx::Point ConstrainedWindowFrameView::GetSystemMenuPoint() const {
+ // Doesn't really matter, since we never show system menus on constrained
+ // windows...
+ gfx::Point system_menu_point(FrameBorderThickness(),
+ NonClientTopBorderHeight());
+ ConvertPointToScreen(this, &system_menu_point);
+ return system_menu_point;
+}
+
+int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) {
+ if (!bounds().Contains(point))
+ return HTNOWHERE;
+
+ int frame_component = container_->GetClientView()->NonClientHitTest(point);
+ if (frame_component != HTNOWHERE)
+ return frame_component;
+
+ // Then see if the point is within any of the window controls.
+ if (close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point))
+ return HTCLOSE;
+
+ int window_component = GetHTComponentForFrame(point, FrameBorderThickness(),
+ NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
+ container_->GetDelegate()->CanResize());
+ // Fall back to the caption if no other component matches.
+ return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
+}
+
+void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size,
+ gfx::Path* window_mask) {
+ DCHECK(window_mask);
+
+ // Redefine the window visible region for the new size.
+ window_mask->moveTo(0, 3);
+ window_mask->lineTo(1, 2);
+ window_mask->lineTo(1, 1);
+ window_mask->lineTo(2, 1);
+ window_mask->lineTo(3, 0);
+
+ window_mask->lineTo(SkIntToScalar(size.width() - 3), 0);
+ window_mask->lineTo(SkIntToScalar(size.width() - 2), 1);
+ window_mask->lineTo(SkIntToScalar(size.width() - 1), 1);
+ window_mask->lineTo(SkIntToScalar(size.width() - 1), 2);
+ window_mask->lineTo(SkIntToScalar(size.width()), 3);
+
+ window_mask->lineTo(SkIntToScalar(size.width()),
+ SkIntToScalar(size.height()));
+ window_mask->lineTo(0, SkIntToScalar(size.height()));
+ window_mask->close();
+}
+
+void ConstrainedWindowFrameView::EnableClose(bool enable) {
+ close_button_->SetEnabled(enable);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView, views::View implementation:
+
+void ConstrainedWindowFrameView::Paint(gfx::Canvas* canvas) {
+ PaintFrameBorder(canvas);
+ PaintTitleBar(canvas);
+ PaintClientEdge(canvas);
+}
+
+void ConstrainedWindowFrameView::Layout() {
+ LayoutWindowControls();
+ LayoutTitleBar();
+ LayoutClientView();
+}
+
+void ConstrainedWindowFrameView::ThemeChanged() {
+ InitWindowResources();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView, views::ButtonListener implementation:
+
+void ConstrainedWindowFrameView::ButtonPressed(views::Button* sender) {
+ if (sender == close_button_)
+ container_->ExecuteSystemMenuCommand(SC_CLOSE);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowFrameView, private:
+
+int ConstrainedWindowFrameView::FrameBorderThickness() const {
+ return kFrameBorderThickness;
+}
+
+int ConstrainedWindowFrameView::NonClientBorderThickness() const {
+ return FrameBorderThickness() + kClientEdgeThickness;
+}
+
+int ConstrainedWindowFrameView::NonClientTopBorderHeight() const {
+ int title_top_spacing, title_thickness;
+ return TitleCoordinates(&title_top_spacing, &title_thickness);
+}
+
+int ConstrainedWindowFrameView::TitleCoordinates(
+ int* title_top_spacing,
+ int* title_thickness) const {
+ int frame_thickness = FrameBorderThickness();
+ int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness;
+ *title_top_spacing = frame_thickness + kTitleTopSpacing;
+ // The bottom spacing should be the same apparent height as the top spacing,
+ // plus have the client edge tacked on.
+ int title_bottom_spacing = *title_top_spacing + kClientEdgeThickness;
+ *title_thickness = std::max(title_font_->height(),
+ min_titlebar_height - *title_top_spacing - title_bottom_spacing);
+ return *title_top_spacing + *title_thickness + title_bottom_spacing;
+}
+
+void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) {
+ SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER);
+ SkBitmap* top_right_corner =
+ resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER);
+ SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE);
+ SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE);
+ SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE);
+ SkBitmap* bottom_left_corner =
+ resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER);
+ SkBitmap* bottom_right_corner =
+ resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER);
+ SkBitmap* bottom_edge = resources_->GetPartBitmap(FRAME_BOTTOM_EDGE);
+
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ SkBitmap* theme_frame = rb.GetBitmapNamed(IDR_THEME_FRAME);
+ SkColor frame_color = ResourceBundle::frame_color;
+
+ // Fill with the frame color first so we have a constant background for
+ // areas not covered by the theme image.
+ canvas->FillRectInt(frame_color, 0, 0, width(), theme_frame->height());
+ // Now fill down the sides
+ canvas->FillRectInt(frame_color,
+ 0, theme_frame->height(),
+ left_edge->width(), height() - theme_frame->height());
+ canvas->FillRectInt(frame_color,
+ width() - right_edge->width(), theme_frame->height(),
+ right_edge->width(), height() - theme_frame->height());
+ // Now fill the bottom area.
+ canvas->FillRectInt(frame_color,
+ left_edge->width(), height() - bottom_edge->height(),
+ width() - left_edge->width() - right_edge->width(),
+ bottom_edge->height());
+
+ // Draw the theme frame.
+ canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height());
+
+ // Top.
+ canvas->DrawBitmapInt(*top_left_corner, 0, 0);
+ canvas->TileImageInt(*top_edge, top_left_corner->width(), 0,
+ width() - top_right_corner->width(), top_edge->height());
+ canvas->DrawBitmapInt(*top_right_corner,
+ width() - top_right_corner->width(), 0);
+
+ // Right.
+ canvas->TileImageInt(*right_edge, width() - right_edge->width(),
+ top_right_corner->height(), right_edge->width(),
+ height() - top_right_corner->height() -
+ bottom_right_corner->height());
+
+ // Bottom.
+ canvas->DrawBitmapInt(*bottom_right_corner,
+ width() - bottom_right_corner->width(),
+ height() - bottom_right_corner->height());
+ canvas->TileImageInt(*bottom_edge, bottom_left_corner->width(),
+ height() - bottom_edge->height(),
+ width() - bottom_left_corner->width() -
+ bottom_right_corner->width(),
+ bottom_edge->height());
+ canvas->DrawBitmapInt(*bottom_left_corner, 0,
+ height() - bottom_left_corner->height());
+
+ // Left.
+ canvas->TileImageInt(*left_edge, 0, top_left_corner->height(),
+ left_edge->width(),
+ height() - top_left_corner->height() - bottom_left_corner->height());
+}
+
+void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) {
+ canvas->DrawStringInt(container_->GetWindowTitle(), *title_font_,
+ GetTitleColor(), MirroredLeftPointForRect(title_bounds_),
+ title_bounds_.y(), title_bounds_.width(), title_bounds_.height());
+}
+
+void ConstrainedWindowFrameView::PaintClientEdge(gfx::Canvas* canvas) {
+ gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height()));
+ client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness);
+ gfx::Rect frame_shadow_bounds(client_edge_bounds);
+ frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness);
+
+ canvas->FillRectInt(kContentsBorderShadow, frame_shadow_bounds.x(),
+ frame_shadow_bounds.y(), frame_shadow_bounds.width(),
+ frame_shadow_bounds.height());
+
+ canvas->FillRectInt(ResourceBundle::toolbar_color, client_edge_bounds.x(),
+ client_edge_bounds.y(), client_edge_bounds.width(),
+ client_edge_bounds.height());
+}
+
+void ConstrainedWindowFrameView::LayoutWindowControls() {
+ gfx::Size close_button_size = close_button_->GetPreferredSize();
+ close_button_->SetBounds(
+ width() - close_button_size.width() - FrameBorderThickness(),
+ kCaptionTopSpacing, close_button_size.width(),
+ close_button_size.height());
+}
+
+void ConstrainedWindowFrameView::LayoutTitleBar() {
+ // Size the title.
+ int title_x = FrameBorderThickness() + kIconLeftSpacing;
+ int title_top_spacing, title_thickness;
+ TitleCoordinates(&title_top_spacing, &title_thickness);
+ title_bounds_.SetRect(title_x,
+ title_top_spacing + ((title_thickness - title_font_->height()) / 2),
+ std::max(0, close_button_->x() - kTitleCaptionSpacing - title_x),
+ title_font_->height());
+}
+
+void ConstrainedWindowFrameView::LayoutClientView() {
+ client_view_bounds_ = CalculateClientAreaBounds(width(), height());
+}
+
+gfx::Rect ConstrainedWindowFrameView::CalculateClientAreaBounds(
+ int width,
+ int height) const {
+ int top_height = NonClientTopBorderHeight();
+ int border_thickness = NonClientBorderThickness();
+ return gfx::Rect(border_thickness, top_height,
+ std::max(0, width - (2 * border_thickness)),
+ std::max(0, height - top_height - border_thickness));
+}
+
+void ConstrainedWindowFrameView::InitWindowResources() {
+ if (win_util::ShouldUseVistaFrame()) {
+ resources_.reset(new VistaWindowResources);
+ } else {
+ resources_.reset(new XPWindowResources);
+ }
+}
+
+// static
+void ConstrainedWindowFrameView::InitClass() {
+ static bool initialized = false;
+ if (!initialized) {
+ title_font_ = new gfx::Font(win_util::GetWindowTitleFont());
+
+ initialized = true;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowImpl, public:
+
+// The space (in pixels) between minimized pop-ups stacked horizontally and
+// vertically.
+static const int kPopupRepositionOffset = 5;
+static const int kConstrainedWindowEdgePadding = 10;
+
+ConstrainedWindowImpl::~ConstrainedWindowImpl() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowImpl, ConstrainedWindow implementation:
+
+views::NonClientFrameView* ConstrainedWindowImpl::CreateFrameViewForWindow() {
+ return new ConstrainedWindowFrameView(this);
+}
+
+void ConstrainedWindowImpl::CloseConstrainedWindow() {
+ // Broadcast to all observers of NOTIFY_CWINDOW_CLOSED.
+ // One example of such an observer is AutomationCWindowTracker in the
+ // automation component.
+ NotificationService::current()->Notify(NotificationType::CWINDOW_CLOSED,
+ Source<ConstrainedWindow>(this),
+ NotificationService::NoDetails());
+
+ Close();
+}
+
+std::wstring ConstrainedWindowImpl::GetWindowTitle() const {
+ std::wstring display_title;
+ if (GetDelegate())
+ display_title = GetDelegate()->GetWindowTitle();
+ else
+ display_title = L"Untitled";
+
+ return display_title;
+}
+
+const gfx::Rect& ConstrainedWindowImpl::GetCurrentBounds() const {
+ return current_bounds_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowImpl, private:
+
+ConstrainedWindowImpl::ConstrainedWindowImpl(
+ TabContents* owner,
+ views::WindowDelegate* window_delegate)
+ : WindowWin(window_delegate),
+ owner_(owner) {
+ GetNonClientView()->SetFrameView(CreateFrameViewForWindow());
+
+ focus_restoration_disabled_ = false;
+ set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION |
+ WS_THICKFRAME | WS_SYSMENU);
+ set_focus_on_creation(false);
+
+ WindowWin::Init(owner_->GetNativeView(), gfx::Rect());
+ ActivateConstrainedWindow();
+}
+
+void ConstrainedWindowImpl::ActivateConstrainedWindow() {
+ // Other pop-ups are simply moved to the front of the z-order.
+ SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowImpl, views::WidgetWin overrides:
+
+void ConstrainedWindowImpl::OnDestroy() {
+ // TODO(jcampan): figure out focus restoration
+
+ // Make sure we call super so that it can do its cleanup.
+ WindowWin::OnDestroy();
+}
+
+void ConstrainedWindowImpl::OnFinalMessage(HWND window) {
+ // Tell our constraining TabContents that we've gone so it can update its
+ // list.
+ owner_->WillClose(this);
+
+ WindowWin::OnFinalMessage(window);
+}
+
+LRESULT ConstrainedWindowImpl::OnMouseActivate(HWND window,
+ UINT hittest_code,
+ UINT message) {
+ // We only detach the window if the user clicked on the title bar. That
+ // way, users can click inside the contents of legitimate popups obtained
+ // with a mouse gesture.
+ if (hittest_code != HTCLIENT && hittest_code != HTNOWHERE &&
+ hittest_code != HTCLOSE) {
+ ActivateConstrainedWindow();
+ }
+
+ return MA_ACTIVATE;
+}
+
+void ConstrainedWindowImpl::OnWindowPosChanged(WINDOWPOS* window_pos) {
+ // If the window was moved or sized, tell the owner.
+ if (!(window_pos->flags & SWP_NOMOVE) || !(window_pos->flags & SWP_NOSIZE))
+ owner_->DidMoveOrResize(this);
+ SetMsgHandled(FALSE);
+}
+
+
+// static
+ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog(
+ TabContents* parent,
+ views::WindowDelegate* window_delegate) {
+ ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent,
+ window_delegate);
+ return window;
+}
diff --git a/chrome/browser/views/download_started_animation_win.cc b/chrome/browser/views/download_started_animation_win.cc
index 4de387e..ec71683 100644
--- a/chrome/browser/views/download_started_animation_win.cc
+++ b/chrome/browser/views/download_started_animation_win.cc
@@ -106,7 +106,7 @@ DownloadStartedAnimationWin::DownloadStartedAnimationWin(
popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW |
WS_EX_TRANSPARENT);
popup_->SetOpacity(0x00);
- popup_->Init(tab_contents_->GetNativeView(), rc, false);
+ popup_->Init(tab_contents_->GetNativeView(), rc);
popup_->SetContentsView(this);
Reposition();
popup_->Show();
diff --git a/chrome/browser/views/find_bar_win.cc b/chrome/browser/views/find_bar_win.cc
index 51e1b20..4272ef7 100644
--- a/chrome/browser/views/find_bar_win.cc
+++ b/chrome/browser/views/find_bar_win.cc
@@ -95,12 +95,13 @@ FindBarWin::FindBarWin(BrowserView* browser_view)
// Initialize the host.
host_.reset(new Host(this));
- host_->Init(browser_view->GetWidget()->GetNativeView(), gfx::Rect(), false);
+ host_->Init(browser_view->GetWidget()->GetNativeView(), gfx::Rect());
host_->SetContentsView(view_);
// Start listening to focus changes, so we can register and unregister our
// own handler for Escape.
- focus_manager_ = views::FocusManager::GetFocusManager(host_->GetNativeView());
+ focus_manager_ =
+ views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView());
focus_manager_->AddFocusChangeListener(this);
// Stores the currently focused view, and tracks focus changes so that we can
diff --git a/chrome/browser/views/find_bar_win_browsertest.cc b/chrome/browser/views/find_bar_win_browsertest.cc
index 67b05ad..cf55acf 100644
--- a/chrome/browser/views/find_bar_win_browsertest.cc
+++ b/chrome/browser/views/find_bar_win_browsertest.cc
@@ -557,8 +557,9 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) {
GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
- views::FocusManager* focus_manager = views::FocusManager::GetFocusManager(
- browser()->window()->GetNativeHandle());
+ gfx::NativeView browser_view = browser()->window()->GetNativeHandle();
+ views::FocusManager* focus_manager =
+ views::FocusManager::GetFocusManagerForNativeView(browser_view);
// See where Escape is registered.
views::Accelerator escape(VK_ESCAPE, false, false, false);
diff --git a/chrome/browser/views/first_run_bubble.cc b/chrome/browser/views/first_run_bubble.cc
index ba8edb2..b79c665 100644
--- a/chrome/browser/views/first_run_bubble.cc
+++ b/chrome/browser/views/first_run_bubble.cc
@@ -343,9 +343,7 @@ void FirstRunBubble::InfoBubbleClosing(InfoBubble* info_bubble,
if (!IsWindowEnabled(GetParent()))
::EnableWindow(GetParent(), true);
enable_window_method_factory_.RevokeAll();
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
- focus_manager->RemoveFocusChangeListener(view_);
+ GetFocusManager()->RemoveFocusChangeListener(view_);
}
// static
@@ -362,9 +360,7 @@ FirstRunBubble* FirstRunBubble::Show(Profile* profile, views::Window* parent,
window->set_view(view);
window->Init(parent, position_relative_to, view);
window->ShowWindow(SW_SHOW);
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(window->GetNativeView());
- focus_manager->AddFocusChangeListener(view);
+ window->GetFocusManager()->AddFocusChangeListener(view);
view->BubbleShown();
return window;
}
diff --git a/chrome/browser/views/fullscreen_exit_bubble.cc b/chrome/browser/views/fullscreen_exit_bubble.cc
index 854c3dd..907a791 100644
--- a/chrome/browser/views/fullscreen_exit_bubble.cc
+++ b/chrome/browser/views/fullscreen_exit_bubble.cc
@@ -144,7 +144,7 @@ FullscreenExitBubble::FullscreenExitBubble(
popup_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW |
l10n_util::GetExtendedTooltipStyles());
popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity));
- popup_->Init(frame->GetNativeView(), GetPopupRect(false), false);
+ popup_->Init(frame->GetNativeView(), GetPopupRect(false));
popup_->SetContentsView(view_);
popup_->Show(); // This does not activate the popup.
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc
index 908aa54..031caaf 100644
--- a/chrome/browser/views/info_bubble.cc
+++ b/chrome/browser/views/info_bubble.cc
@@ -133,7 +133,7 @@ void InfoBubble::Init(views::Window* parent,
content_view_->CalculateWindowBoundsAndAjust(position_relative_to);
#if defined(OS_WIN)
- WidgetWin::Init(parent->GetNativeWindow(), bounds, true);
+ WidgetWin::Init(parent->GetNativeWindow(), bounds);
#else
WidgetGtk::Init(GTK_WIDGET(parent->GetNativeWindow()), bounds, true);
#endif
@@ -155,11 +155,9 @@ void InfoBubble::Init(views::Window* parent,
#if defined(OS_WIN)
// Register the Escape accelerator for closing.
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
- focus_manager->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false,
- false, false),
- this);
+ GetFocusManager()->RegisterAccelerator(views::Accelerator(VK_ESCAPE, false,
+ false, false),
+ this);
// Set initial alpha value of the layered window.
SetLayeredWindowAttributes(GetNativeView(),
RGB(0xFF, 0xFF, 0xFF),
diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc
index 12fe42e..3e19bf7 100644
--- a/chrome/browser/views/infobars/infobars.cc
+++ b/chrome/browser/views/infobars/infobars.cc
@@ -207,9 +207,8 @@ void InfoBar::InfoBarAdded() {
// focus so that we can restore focus when we're removed.
views::Widget* widget = GetWidget();
if (widget) {
- focus_tracker_.reset(
- new views::ExternalFocusTracker(this,
- views::FocusManager::GetFocusManager(widget->GetNativeView())));
+ focus_tracker_.reset(new views::ExternalFocusTracker(this,
+ GetFocusManager()));
}
#endif
}
diff --git a/chrome/browser/views/shelf_item_dialog.cc b/chrome/browser/views/shelf_item_dialog.cc
index ade3be7..12868f6 100644
--- a/chrome/browser/views/shelf_item_dialog.cc
+++ b/chrome/browser/views/shelf_item_dialog.cc
@@ -476,8 +476,7 @@ bool ShelfItemDialog::AcceleratorPressed(
if (accelerator.GetKeyCode() == VK_ESCAPE) {
window()->Close();
} else if (accelerator.GetKeyCode() == VK_RETURN) {
- views::FocusManager* fm = views::FocusManager::GetFocusManager(
- GetWidget()->GetNativeView());
+ views::FocusManager* fm = GetFocusManager();
if (fm->GetFocusedView() == url_table_) {
// Return on table behaves like a double click.
OnDoubleClick();
diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc
index 49462bf..76c3ab9 100644
--- a/chrome/browser/views/status_bubble_views.cc
+++ b/chrome/browser/views/status_bubble_views.cc
@@ -481,7 +481,7 @@ void StatusBubbleViews::Init() {
WS_EX_TRANSPARENT |
l10n_util::GetExtendedTooltipStyles());
popup->SetOpacity(0x00);
- popup->Init(frame_->GetNativeView(), gfx::Rect(), false);
+ popup->Init(frame_->GetNativeView(), gfx::Rect());
popup->SetContentsView(view_);
Reposition();
popup->Show();
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
index 1b7fa80..2080cff 100755
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -73,7 +73,7 @@ void TabContentsViewWin::CreateView() {
// Since we create these windows parented to the desktop window initially, we
// don't want to create them initially visible.
set_window_style(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
- WidgetWin::Init(GetDesktopWindow(), gfx::Rect(), false);
+ WidgetWin::Init(GetDesktopWindow(), gfx::Rect());
// Remove the root view drop target so we can register our own.
RevokeDragDrop(GetNativeView());
@@ -233,7 +233,7 @@ void TabContentsViewWin::SizeContents(const gfx::Size& size) {
void TabContentsViewWin::Focus() {
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
if (tab_contents()->interstitial_page()) {
tab_contents()->interstitial_page()->Focus();
@@ -269,7 +269,7 @@ void TabContentsViewWin::StoreFocus() {
view_storage->RemoveView(last_focused_view_storage_id_);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
if (focus_manager) {
// |focus_manager| can be NULL if the tab has been detached but still
// exists.
@@ -301,7 +301,7 @@ void TabContentsViewWin::RestoreFocus() {
SetInitialFocus();
} else {
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
+ 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.";
@@ -333,7 +333,7 @@ void TabContentsViewWin::GotFocus() {
void TabContentsViewWin::TakeFocus(bool reverse) {
if (!tab_contents()->delegate()->TakeFocus(reverse)) {
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
// We may not have a focus manager if the tab has been switched before this
// message arrived.
@@ -357,7 +357,7 @@ void TabContentsViewWin::HandleKeyboardEvent(
// a keyboard shortcut that we have to process.
if (event.type == WebInputEvent::RawKeyDown) {
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
// We may not have a focus_manager at this point (if the tab has been
// switched by the time this message returned).
if (focus_manager) {
diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc
index b4fea1d..adf7903 100644
--- a/chrome/browser/views/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/views/tabs/dragged_tab_controller.cc
@@ -198,7 +198,7 @@ class DraggedTabController::DockDisplayer : public AnimationDelegate {
popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW |
WS_EX_TOPMOST);
popup->SetOpacity(0x00);
- popup->Init(NULL, info.GetPopupRect(), false);
+ popup->Init(NULL, info.GetPopupRect());
popup->SetContentsView(new DockView(info.type()));
if (info.in_enable_area())
animation_.Reset(1);
diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc
index f3101d9..b77ace5 100644
--- a/chrome/browser/views/tabs/dragged_tab_view.cc
+++ b/chrome/browser/views/tabs/dragged_tab_view.cc
@@ -48,7 +48,7 @@ DraggedTabView::DraggedTabView(TabContents* datasource,
container_->set_window_ex_style(
WS_EX_LAYERED | WS_EX_TOPMOST | WS_EX_TOOLWINDOW);
container_->set_can_update_layered_window(false);
- container_->Init(NULL, gfx::Rect(0, 0, 0, 0), false);
+ container_->Init(NULL, gfx::Rect(0, 0, 0, 0));
container_->SetContentsView(this);
BOOL drag;
diff --git a/chrome/browser/views/tabs/native_view_photobooth_win.cc b/chrome/browser/views/tabs/native_view_photobooth_win.cc
index 430e009..6f78ea9 100644
--- a/chrome/browser/views/tabs/native_view_photobooth_win.cc
+++ b/chrome/browser/views/tabs/native_view_photobooth_win.cc
@@ -155,7 +155,7 @@ void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) {
// WS_EX_TOOLWINDOW ensures the capture window doesn't produce a Taskbar
// button.
capture_window_->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW);
- capture_window_->Init(NULL, capture_bounds, false);
+ capture_window_->Init(NULL, capture_bounds);
// If the capture window isn't visible, blitting from the TabContents'
// HWND's DC to the capture bitmap produces blankness.
capture_window_->Show();
diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc
index d669be3..b5f0aae 100644
--- a/chrome/browser/views/tabs/tab_strip.cc
+++ b/chrome/browser/views/tabs/tab_strip.cc
@@ -1382,8 +1382,7 @@ TabStrip::DropInfo::DropInfo(int drop_index, bool drop_before, bool point_down)
arrow_window->Init(
NULL,
- gfx::Rect(0, 0, drop_indicator_width, drop_indicator_height),
- true);
+ gfx::Rect(0, 0, drop_indicator_width, drop_indicator_height));
arrow_window->SetContentsView(arrow_view);
#else
NOTIMPLEMENTED();
diff --git a/views/controls/menu/chrome_menu.cc b/views/controls/menu/chrome_menu.cc
index b05552f..f6e3950 100644
--- a/views/controls/menu/chrome_menu.cc
+++ b/views/controls/menu/chrome_menu.cc
@@ -685,7 +685,7 @@ class MenuHost : public WidgetWin {
const gfx::Rect& bounds,
View* contents_view,
bool do_capture) {
- WidgetWin::Init(parent, bounds, true);
+ WidgetWin::Init(parent, bounds);
SetContentsView(contents_view);
// We don't want to take focus away from the hosting window.
ShowWindow(SW_SHOWNA);
diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc
index 2df961e..5fd8349 100644
--- a/views/controls/native_control.cc
+++ b/views/controls/native_control.cc
@@ -367,8 +367,7 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message,
return 0;
} else if (message == WM_SETFOCUS) {
// Let the focus manager know that the focus changed.
- FocusManager* focus_manager =
- FocusManager::GetFocusManager(native_control->GetNativeControlHWND());
+ FocusManager* focus_manager = native_control->GetFocusManager();
if (focus_manager) {
focus_manager->SetFocusedView(native_control);
} else {
diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc
index b6111fd..32c7261 100644
--- a/views/controls/native_control_win.cc
+++ b/views/controls/native_control_win.cc
@@ -196,8 +196,7 @@ LRESULT NativeControlWin::NativeControlWndProc(HWND window,
return 0;
} else if (message == WM_SETFOCUS) {
// Let the focus manager know that the focus changed.
- FocusManager* focus_manager =
- FocusManager::GetFocusManager(native_control->native_view());
+ FocusManager* focus_manager = native_control->GetFocusManager();
if (focus_manager) {
focus_manager->SetFocusedView(native_control->focus_view());
} else {
diff --git a/views/controls/tabbed_pane.cc b/views/controls/tabbed_pane.cc
index a162131..b7c41bc 100644
--- a/views/controls/tabbed_pane.cc
+++ b/views/controls/tabbed_pane.cc
@@ -172,7 +172,7 @@ HWND TabbedPane::CreateNativeControl(HWND parent_container) {
// Create the view container which is a child of the TabControl.
content_window_ = new WidgetWin();
- content_window_->Init(tab_control_, gfx::Rect(), false);
+ content_window_->Init(tab_control_, gfx::Rect());
// Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above
// for a thorough explanation regarding why we waited until |content_window_|
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index 1ccf651..cda6629 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -681,8 +681,7 @@ void NativeTextfieldWin::OnPaste() {
void NativeTextfieldWin::OnSetFocus(HWND hwnd) {
SetMsgHandled(FALSE); // We still want the default processing of the message.
- views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(m_hWnd);
+ views::FocusManager* focus_manager = textfield_->GetFocusManager();
if (!focus_manager) {
NOTREACHED();
return;
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index 95a7210..5a2fb42 100755
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -471,13 +471,11 @@ bool TreeView::OnKeyDown(int virtual_key_code) {
} else if (virtual_key_code == VK_RETURN && !process_enter_) {
Widget* widget = GetWidget();
DCHECK(widget);
- FocusManager* fm = FocusManager::GetFocusManager(widget->GetNativeView());
- DCHECK(fm);
Accelerator accelerator(Accelerator(static_cast<int>(virtual_key_code),
win_util::IsShiftPressed(),
win_util::IsCtrlPressed(),
win_util::IsAltPressed()));
- fm->ProcessAccelerator(accelerator);
+ GetFocusManager()->ProcessAccelerator(accelerator);
return true;
}
return false;
diff --git a/views/focus/external_focus_tracker.cc b/views/focus/external_focus_tracker.cc
index 8f8bfdf..b08d287 100644
--- a/views/focus/external_focus_tracker.cc
+++ b/views/focus/external_focus_tracker.cc
@@ -4,6 +4,7 @@
#include "views/focus/external_focus_tracker.h"
+#include "base/logging.h"
#include "views/view.h"
#include "views/focus/view_storage.h"
@@ -13,6 +14,8 @@ ExternalFocusTracker::ExternalFocusTracker(View* parent_view,
FocusManager* focus_manager)
: focus_manager_(focus_manager),
parent_view_(parent_view) {
+ DCHECK(focus_manager);
+ DCHECK(parent_view);
view_storage_ = ViewStorage::GetSharedInstance();
last_focused_view_storage_id_ = view_storage_->CreateStorageID();
// Store the view which is focused when we're created.
diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc
index f4b67ff..dc26649 100644
--- a/views/focus/focus_manager.cc
+++ b/views/focus/focus_manager.cc
@@ -12,7 +12,6 @@
#include <gtk/gtk.h>
#endif
-#include "base/histogram.h"
#include "base/logging.h"
#include "views/accelerator.h"
#include "views/focus/view_storage.h"
@@ -24,158 +23,17 @@
#include "base/win_util.h"
#endif
-// The following keys are used in SetProp/GetProp to associate additional
-// information needed for focus tracking with a window.
-
-// Maps to the FocusManager instance for a top level window. See
-// CreateFocusManager/DestoryFocusManager for usage.
-static const wchar_t* const kFocusManagerKey = L"__VIEW_CONTAINER__";
-
-// Maps to the View associated with a window.
-// We register views with window so we can:
-// - keep in sync the native focus with the view focus (when the native
-// component gets the focus, we get the WM_SETFOCUS event and we can focus the
-// associated view).
-// - prevent tab key events from being sent to views.
-static const wchar_t* const kViewKey = L"__CHROME_VIEW__";
-
-// A property set to 1 to indicate whether the focus manager has subclassed that
-// window. We are doing this to ensure we are not subclassing several times.
-// Subclassing twice is not a problem if no one is subclassing the HWND between
-// the 2 subclassings (the 2nd subclassing is ignored since the WinProc is the
-// same as the current one). However if some other app goes and subclasses the
-// HWND between the 2 subclassings, we will end up subclassing twice.
-// This flag lets us test that whether we have or not subclassed yet.
-static const wchar_t* const kFocusSubclassInstalled =
- L"__FOCUS_SUBCLASS_INSTALLED__";
-
namespace views {
-#if defined(OS_WIN)
-// Callback installed via InstallFocusSubclass.
-static LRESULT CALLBACK FocusWindowCallback(HWND window, UINT message,
- WPARAM wParam, LPARAM lParam) {
- if (!::IsWindow(window)) {
- // QEMU has reported crashes when calling GetProp (this seems to happen for
- // some weird messages, not sure what they are).
- // Here we are just trying to avoid the crasher.
- NOTREACHED();
- return 0;
- }
-
- WNDPROC original_handler = win_util::GetSuperclassWNDPROC(window);
- DCHECK(original_handler);
- FocusManager* focus_manager = FocusManager::GetFocusManager(window);
- // There are cases when we have no FocusManager for the window. This happens
- // because we subclass certain windows (such as the TabContents window)
- // but that window may not have an associated FocusManager.
- if (focus_manager) {
- switch (message) {
- case WM_NCDESTROY:
- if (!focus_manager->OnNCDestroy(window))
- return 0;
- break;
- default:
- break;
- }
- }
- return CallWindowProc(original_handler, window, message, wParam, lParam);
-}
-
-#endif
-
// FocusManager -----------------------------------------------------
-#if defined(OS_WIN)
-// static
-FocusManager* FocusManager::CreateFocusManager(HWND window,
- RootView* root_view) {
- DCHECK(window);
- DCHECK(root_view);
- InstallFocusSubclass(window, NULL);
- FocusManager* focus_manager = new FocusManager(window, root_view);
- SetProp(window, kFocusManagerKey, focus_manager);
-
- return focus_manager;
-}
-
-// static
-void FocusManager::InstallFocusSubclass(HWND window, View* view) {
- DCHECK(window);
-
- bool already_subclassed =
- reinterpret_cast<bool>(GetProp(window,
- kFocusSubclassInstalled));
- if (already_subclassed &&
- !win_util::IsSubclassed(window, &FocusWindowCallback)) {
- NOTREACHED() << "window sub-classed by someone other than the FocusManager";
- // Track in UMA so we know if this case happens.
- UMA_HISTOGRAM_COUNTS("FocusManager.MultipleSubclass", 1);
- } else {
- win_util::Subclass(window, &FocusWindowCallback);
- SetProp(window, kFocusSubclassInstalled, reinterpret_cast<HANDLE>(true));
- }
- if (view)
- SetProp(window, kViewKey, view);
-}
-
-void FocusManager::UninstallFocusSubclass(HWND window) {
- DCHECK(window);
- if (win_util::Unsubclass(window, &FocusWindowCallback)) {
- RemoveProp(window, kViewKey);
- RemoveProp(window, kFocusSubclassInstalled);
- }
-}
-
-#endif
-
-// static
-FocusManager* FocusManager::GetFocusManager(gfx::NativeView window) {
-#if defined(OS_WIN)
- DCHECK(window);
-
- // In case parent windows belong to a different process, yet
- // have the kFocusManagerKey property set, we have to be careful
- // to also check the process id of the window we're checking.
- DWORD window_pid = 0, current_pid = GetCurrentProcessId();
- FocusManager* focus_manager;
- for (focus_manager = NULL; focus_manager == NULL && IsWindow(window);
- window = GetParent(window)) {
- GetWindowThreadProcessId(window, &window_pid);
- if (current_pid != window_pid)
- break;
- focus_manager = reinterpret_cast<FocusManager*>(
- GetProp(window, kFocusManagerKey));
- }
- return focus_manager;
-#else
- NOTIMPLEMENTED();
- return NULL;
-#endif
-}
-
-#if defined(OS_WIN)
-// static
-View* FocusManager::GetViewForWindow(gfx::NativeView window, bool look_in_parents) {
- DCHECK(window);
- do {
- View* v = reinterpret_cast<View*>(GetProp(window, kViewKey));
- if (v)
- return v;
- } while (look_in_parents && (window = ::GetParent(window)));
- return NULL;
-}
-
-FocusManager::FocusManager(HWND root, RootView* root_view)
- : root_(root),
- top_root_view_(root_view),
- focused_view_(NULL),
- ignore_set_focus_msg_(false) {
+FocusManager::FocusManager(Widget* widget)
+ : widget_(widget),
+ focused_view_(NULL) {
+ DCHECK(widget_);
stored_focused_view_storage_id_ =
ViewStorage::GetSharedInstance()->CreateStorageID();
- DCHECK(root_);
}
-#endif
FocusManager::~FocusManager() {
// If there are still registered FocusChange listeners, chances are they were
@@ -185,29 +43,12 @@ FocusManager::~FocusManager() {
#if defined(OS_WIN)
// Message handlers.
-bool FocusManager::OnNCDestroy(HWND window) {
- // Window is being destroyed, undo the subclassing.
- FocusManager::UninstallFocusSubclass(window);
-
- if (window == root_) {
- // We are the top window.
-
- DCHECK(GetProp(window, kFocusManagerKey));
-
- // Make sure this is called on the window that was set with the
- // FocusManager.
- RemoveProp(window, kFocusManagerKey);
-
- delete this;
- }
- return true;
-}
-
bool FocusManager::OnKeyDown(HWND window, UINT message, WPARAM wparam,
LPARAM lparam) {
DCHECK((message == WM_KEYDOWN) || (message == WM_SYSKEYDOWN));
+ HWND hwnd = widget_->GetNativeView();
- if (!IsWindowVisible(root_)) {
+ if (!IsWindowVisible(hwnd)) {
// We got a message for a hidden window. Because WidgetWin::Close hides the
// window, then destroys it, it it possible to get a message after we've
// hidden the window. If we allow the message to be dispatched chances are
@@ -245,9 +86,10 @@ bool FocusManager::OnKeyDown(HWND window, UINT message, WPARAM wparam,
// Note that we don't do focus traversal if the root window is not part of the
// active window hierarchy as this would mean we have no focused view and
// would focus the first focusable view.
+ HWND top_window = widget_->GetNativeView();
HWND active_window = ::GetActiveWindow();
- if ((active_window == root_ || ::IsChild(active_window, root_)) &&
- IsTabTraversalKeyEvent(key_event)) {
+ if ((active_window == top_window || ::IsChild(active_window, top_window)) &&
+ IsTabTraversalKeyEvent(key_event)) {
AdvanceFocus(win_util::IsShiftPressed());
return false;
}
@@ -324,9 +166,10 @@ bool FocusManager::ContainsView(View* view) {
if (!widget)
return false;
+ gfx::NativeView top_window = widget_->GetNativeView();
gfx::NativeView window = widget->GetNativeView();
while (window) {
- if (window == root_)
+ if (window == top_window)
return true;
#if defined(OS_WIN)
window = ::GetParent(window);
@@ -377,7 +220,7 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view,
starting_view = original_starting_view;
}
} else {
- focus_traversable = top_root_view_;
+ focus_traversable = widget_->GetRootView();
}
// Traverse the FocusTraversable tree down to find the focusable view.
@@ -457,30 +300,9 @@ void FocusManager::SetFocusedView(View* view) {
void FocusManager::ClearFocus() {
SetFocusedView(NULL);
- ClearHWNDFocus();
+ ClearNativeFocus();
}
-void FocusManager::ClearHWNDFocus() {
- // Keep the top root window focused so we get keyboard events.
- ignore_set_focus_msg_ = true;
-#if defined(OS_WIN)
- ::SetFocus(root_);
-#else
- NOTIMPLEMENTED();
-#endif
- ignore_set_focus_msg_ = false;
-}
-
-#if defined(OS_WIN)
-void FocusManager::FocusHWND(HWND hwnd) {
- ignore_set_focus_msg_ = true;
- // Only reset focus if hwnd is not already focused.
- if (hwnd && ::GetFocus() != hwnd)
- ::SetFocus(hwnd);
- ignore_set_focus_msg_ = false;
-}
-#endif
-
void FocusManager::StoreFocusedView() {
ViewStorage* view_storage = ViewStorage::GetSharedInstance();
if (!view_storage) {
@@ -535,19 +357,6 @@ void FocusManager::ClearStoredFocusedView() {
view_storage->RemoveView(stored_focused_view_storage_id_);
}
-FocusManager* FocusManager::GetParentFocusManager() const {
-#if defined(OS_WIN)
- HWND parent = ::GetParent(root_);
-#else
- GtkWidget* parent = gtk_widget_get_parent(root_);
-#endif
- // If we are a top window, we don't have a parent FocusManager.
- if (!parent)
- return NULL;
-
- return GetFocusManager(parent);
-}
-
// Find the next (previous if reverse is true) focusable view for the specified
// FocusTraversable, starting at the specified view, traversing down the
// FocusTraversable hierarchy.
@@ -629,13 +438,6 @@ bool FocusManager::ProcessAccelerator(const Accelerator& accelerator) {
}
}
- // When dealing with child windows that have their own FocusManager (such
- // as ConstrainedWindow), we still want the parent FocusManager to process
- // the accelerator if the child window did not process it.
- FocusManager* parent_focus_manager = GetParentFocusManager();
- if (parent_focus_manager)
- return parent_focus_manager->ProcessAccelerator(accelerator);
-
return false;
}
diff --git a/views/focus/focus_manager.h b/views/focus/focus_manager.h
index fb48188..8b4c8c9a 100644
--- a/views/focus/focus_manager.h
+++ b/views/focus/focus_manager.h
@@ -20,7 +20,7 @@
// focused views and handle keyboard accelerators.
//
// There are 2 types of focus:
-// - the native focus, which is the focus that an HWND has.
+// - the native focus, which is the focus that an gfx::NativeView has.
// - the view focus, which is the focus that a views::View has.
//
// Each native view must register with their Focus Manager so the focus manager
@@ -32,13 +32,9 @@
// This is already done for you if you subclass the NativeControl class or if
// you use the NativeViewHost class.
//
-// When creating a top window, if it derives from WidgetWin, the
-// |has_own_focus_manager| of the Init method lets you specify whether that
-// window should have its own focus manager (so focus traversal stays confined
-// in that window). If you are not deriving from WidgetWin or one of its
-// derived classes (Window, FramelessWindow, ConstrainedWindow), you must
-// create a FocusManager when the window is created (it is automatically deleted
-// when the window is destroyed).
+// When creating a top window (derived from views::Widget) that is not a child
+// window, it creates and owns a FocusManager to manage the focus for itself and
+// all its child windows.
//
// The FocusTraversable interface exposes the methods a class should implement
// in order to be able to be focus traversed when tab key is pressed.
@@ -77,8 +73,9 @@
namespace views {
-class View;
class RootView;
+class View;
+class Widget;
// The FocusTraversable interface is used by components that want to process
// focus traversal events (due to Tab/Shift-Tab key events).
@@ -153,22 +150,10 @@ class FocusChangeListener {
class FocusManager {
public:
-#if defined(OS_WIN)
- // Creates a FocusManager for the specified window. Top level windows
- // must invoked this when created.
- // The RootView specified should be the top RootView of the window.
- // This also invokes InstallFocusSubclass.
- static FocusManager* CreateFocusManager(HWND window, RootView* root_view);
-#endif
-
- static FocusManager* GetFocusManager(gfx::NativeView window);
+ explicit FocusManager(Widget* widget);
+ ~FocusManager();
#if defined(OS_WIN)
- // Message handlers (for messages received from registered windows).
- // Should return true if the message should be forwarded to the window
- // original proc function, false otherwise.
- bool OnSetFocus(HWND window);
- bool OnNCDestroy(HWND window);
// OnKeyDown covers WM_KEYDOWN and WM_SYSKEYDOWN.
bool OnKeyDown(HWND window,
UINT message,
@@ -195,27 +180,10 @@ class FocusManager {
// the native focus (so we still get keyboard events).
void ClearFocus();
- // Clears the HWND that has the focus by focusing the HWND from the top
- // RootView (so we still get keyboard events).
- // Note that this does not change the currently focused view.
- void ClearHWNDFocus();
-
-#if defined(OS_WIN)
- // Focus the specified |hwnd| without changing the focused view.
- void FocusHWND(HWND hwnd);
-#endif
-
// Validates the focused view, clearing it if the window it belongs too is not
// attached to the window hierarchy anymore.
void ValidateFocusedView();
-#if defined(OS_WIN)
- // Returns the view associated with the specified window if any.
- // If |look_in_parents| is true, it goes up the window parents until it find
- // a view.
- static View* GetViewForWindow(HWND window, bool look_in_parents);
-#endif
-
// Stores and restores the focused view. Used when the window becomes
// active/inactive.
void StoreFocusedView();
@@ -224,11 +192,6 @@ class FocusManager {
// Clears the stored focused view.
void ClearStoredFocusedView();
- // Returns the FocusManager of the parent window of the window that is the
- // root of this FocusManager. This is useful with ConstrainedWindows that have
- // their own FocusManager and need to return focus to the browser when closed.
- FocusManager* GetParentFocusManager() const;
-
// Register a keyboard accelerator for the specified target. If multiple
// targets are registered for an accelerator, a target registered later has
// higher priority.
@@ -280,22 +243,17 @@ class FocusManager {
// pressed).
static bool IsTabTraversalKeyEvent(const KeyEvent& key_event);
- private:
-#if defined(OS_WIN)
- explicit FocusManager(HWND root, RootView* root_view);
+ // Sets the focus to the specified native view.
+ virtual void FocusNativeView(gfx::NativeView native_view);
- // Subclasses the specified window. The subclassed window procedure listens
- // for WM_SETFOCUS notification and keeps the FocusManager's focus owner
- // property in sync.
- // It's not necessary to explicitly invoke Uninstall, it's automatically done
- // when the window is destroyed and Uninstall wasn't invoked.
- static void InstallFocusSubclass(HWND window, View* view);
+ // Clears the native view having the focus.
+ virtual void ClearNativeFocus();
- // Uninstalls the window subclass installed by InstallFocusSubclass.
- static void UninstallFocusSubclass(HWND window);
-#endif
- ~FocusManager();
+ // Retrieves the FocusManager associated with the passed native view.
+ static FocusManager* GetFocusManagerForNativeView(
+ gfx::NativeView native_view);
+ private:
// Returns the next focusable view.
View* GetNextFocusableView(View* starting_view, bool reverse, bool dont_loop);
@@ -307,8 +265,8 @@ class FocusManager {
View* starting_view,
bool reverse);
- // The RootView of the window associated with this FocusManager.
- RootView* top_root_view_;
+ // The top-level Widget this FocusManager is associated with.
+ Widget* widget_;
// The view that currently is focused.
View* focused_view_;
@@ -317,13 +275,6 @@ class FocusManager {
// had focus.
int stored_focused_view_storage_id_;
- // The window associated with this focus manager.
- gfx::NativeView root_;
-
- // Used to allow setting the focus on an HWND without changing the currently
- // focused view.
- bool ignore_set_focus_msg_;
-
// The accelerators and associated targets.
typedef std::list<AcceleratorTarget*> AcceleratorTargetList;
typedef std::map<Accelerator, AcceleratorTargetList> AcceleratorMap;
diff --git a/views/focus/focus_manager_gtk.cc b/views/focus/focus_manager_gtk.cc
new file mode 100644
index 0000000..f6454d2
--- /dev/null
+++ b/views/focus/focus_manager_gtk.cc
@@ -0,0 +1,25 @@
+// Copyright (c) 2006-2009 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 "views/focus/focus_manager.h"
+
+#include "base/logging.h"
+
+namespace views {
+
+void FocusManager::ClearNativeFocus() {
+ NOTIMPLEMENTED();
+}
+
+void FocusManager::FocusNativeView(gfx::NativeView native_view) {
+ NOTIMPLEMENTED();
+}
+
+// static
+FocusManager* FocusManager::GetFocusManagerForNativeView(
+ gfx::NativeView native_view) {
+ NOTIMPLEMENTED();
+}
+
+} // namespace views
diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc
index cc56271..7fff0bd 100644
--- a/views/focus/focus_manager_unittest.cc
+++ b/views/focus/focus_manager_unittest.cc
@@ -119,7 +119,7 @@ class BorderView : public NativeControl {
parent_container, NULL, NULL, NULL);
// Create the view container which is a child of the TabControl.
widget_ = new WidgetWin();
- widget_->Init(tab_control, gfx::Rect(), false);
+ widget_->Init(tab_control, gfx::Rect());
widget_->SetContentsView(child_);
widget_->SetFocusTraversableParentView(this);
ResizeContents(tab_control);
@@ -210,7 +210,8 @@ class FocusManagerTest : public testing::Test, public WindowDelegate {
}
FocusManager* GetFocusManager() {
- return FocusManager::GetFocusManager(window_->GetNativeWindow());
+ return FocusManager::GetFocusManagerForNativeView(
+ window_->GetNativeWindow());
}
// WindowDelegate Implementation.
diff --git a/views/focus/focus_manager_win.cc b/views/focus/focus_manager_win.cc
new file mode 100644
index 0000000..a3d01f9
--- /dev/null
+++ b/views/focus/focus_manager_win.cc
@@ -0,0 +1,33 @@
+// Copyright (c) 2006-2009 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 "views/focus/focus_manager.h"
+
+#include "views/view.h"
+#include "views/widget/widget_win.h"
+
+namespace views {
+
+void FocusManager::ClearNativeFocus() {
+ // Keep the top root window focused so we get keyboard events.
+ ::SetFocus(widget_->GetNativeView());
+}
+
+void FocusManager::FocusNativeView(gfx::NativeView native_view) {
+ // Only reset focus if hwnd is not already focused.
+ if (native_view && ::GetFocus() != native_view)
+ ::SetFocus(native_view);
+}
+
+// static
+FocusManager* FocusManager::GetFocusManagerForNativeView(
+ gfx::NativeView native_view) {
+ HWND root = ::GetAncestor(native_view, GA_ROOT);
+ if (!root)
+ return NULL;
+ WidgetWin* widget = WidgetWin::GetWidget(root);
+ return widget ? widget->GetFocusManager() : NULL;
+}
+
+} // namespace views
diff --git a/views/view.cc b/views/view.cc
index 0280aef..820f3ec 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -264,6 +264,11 @@ void View::SetFocusable(bool focusable) {
focusable_ = focusable;
}
+FocusManager* View::GetFocusManager() {
+ Widget* widget = GetWidget();
+ return widget ? widget->GetFocusManager() : NULL;
+}
+
bool View::HasFocus() {
FocusManager* focus_manager = GetFocusManager();
if (focus_manager)
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index 6484653..829c682 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -306,7 +306,7 @@ TEST_F(ViewTest, MouseEvent) {
views::WidgetWin window;
window.set_delete_on_destroy(false);
window.set_window_style(WS_OVERLAPPEDWINDOW);
- window.Init(NULL, gfx::Rect(50, 50, 650, 650), false);
+ window.Init(NULL, gfx::Rect(50, 50, 650, 650));
RootView* root = window.GetRootView();
root->AddChildView(v1);
@@ -647,7 +647,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
Clipboard clipboard;
WidgetWin* window = new WidgetWin;
- window->Init(NULL, gfx::Rect(0, 0, 100, 100), true);
+ window->Init(NULL, gfx::Rect(0, 0, 100, 100));
RootView* root_view = window->GetRootView();
Textfield* normal = new Textfield();
@@ -769,7 +769,7 @@ TEST_F(ViewTest, ActivateAccelerator) {
// Create a window and add the view as its child.
WidgetWin window;
- window.Init(NULL, gfx::Rect(0, 0, 100, 100), true);
+ window.Init(NULL, gfx::Rect(0, 0, 100, 100));
window.set_delete_on_destroy(false);
window.set_window_style(WS_OVERLAPPEDWINDOW);
RootView* root = window.GetRootView();
@@ -777,7 +777,7 @@ TEST_F(ViewTest, ActivateAccelerator) {
// Get the focus manager.
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManager(window.GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(window.GetNativeView());
ASSERT_TRUE(focus_manager);
// Hit the return key and see if it takes effect.
@@ -1032,7 +1032,7 @@ class DefaultButtonTest : public ViewTest {
dialog_view_);
window->Show();
native_window_ = window->GetNativeWindow();
- focus_manager_ = FocusManager::GetFocusManager(native_window_);
+ focus_manager_ = FocusManager::GetFocusManagerForNativeView(native_window_);
client_view_ =
static_cast<views::DialogClientView*>(window->GetClientView());
ok_button_ = client_view_->ok_button();
diff --git a/views/view_win.cc b/views/view_win.cc
index c61363d..bf265f9 100644
--- a/views/view_win.cc
+++ b/views/view_win.cc
@@ -17,18 +17,6 @@
namespace views {
-FocusManager* View::GetFocusManager() {
- Widget* widget = GetWidget();
- if (!widget)
- return NULL;
-
- HWND hwnd = widget->GetNativeView();
- if (!hwnd)
- return NULL;
-
- return FocusManager::GetFocusManager(hwnd);
-}
-
void View::DoDrag(const MouseEvent& e, int press_x, int press_y) {
int drag_operations = GetDragOperations(press_x, press_y);
if (drag_operations == DragDropTypes::DRAG_NONE)
@@ -55,7 +43,7 @@ void View::Focus() {
// messages.
FocusManager* focus_manager = GetFocusManager();
if (focus_manager)
- focus_manager->FocusHWND(GetRootView()->GetWidget()->GetNativeView());
+ focus_manager->FocusNativeView(GetRootView()->GetWidget()->GetNativeView());
}
int View::GetHorizontalDragThreshold() {
diff --git a/views/views.gyp b/views/views.gyp
index b83ccae..8715403 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -42,9 +42,9 @@
'type': '<(library)',
'msvs_guid': '6F9258E5-294F-47B2-919D-17FFE7A8B751',
'dependencies': [
- '../app/app.gyp:app_base',
- '../app/app.gyp:app_strings',
- '../app/app.gyp:app_resources',
+ '../app/app.gyp:app_base',
+ '../app/app.gyp:app_strings',
+ '../app/app.gyp:app_resources',
'../skia/skia.gyp:skia',
'../third_party/icu38/icu38.gyp:icui18n',
'../third_party/icu38/icu38.gyp:icuuc',
@@ -174,6 +174,8 @@
'fill_layout.h',
'focus/external_focus_tracker.cc',
'focus/external_focus_tracker.h',
+ 'focus/focus_manager_gtk.cc',
+ 'focus/focus_manager_win.cc',
'focus/focus_manager.cc',
'focus/focus_manager.h',
'focus/focus_util_win.cc',
diff --git a/views/widget/accelerator_handler.cc b/views/widget/accelerator_handler.cc
index 386357f..c171b50 100644
--- a/views/widget/accelerator_handler.cc
+++ b/views/widget/accelerator_handler.cc
@@ -15,7 +15,8 @@ bool AcceleratorHandler::Dispatch(const MSG& msg) {
bool process_message = true;
if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) {
- FocusManager* focus_manager = FocusManager::GetFocusManager(msg.hwnd);
+ FocusManager* focus_manager =
+ FocusManager::GetFocusManagerForNativeView(msg.hwnd);
if (focus_manager) {
// FocusManager::OnKeyDown and OnKeyUp return false if this message has
// been consumed and should not be propagated further.
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 367c720..751786a 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -46,7 +46,7 @@ class PaintTask : public Task {
// The target root view.
RootView* root_view_;
- DISALLOW_EVIL_CONSTRUCTORS(PaintTask);
+ DISALLOW_COPY_AND_ASSIGN(PaintTask);
};
const char RootView::kViewClassName[] = "views/RootView";
@@ -262,23 +262,11 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
default_keyboard_handler_ = NULL;
}
- // For a given widget hierarchy, focus is tracked by a FocusManager attached
- // to our nearest enclosing Window. <-- Important Assumption!
- // We may not have access to our window if this function is called as a
- // result of teardown during the deletion of the RootView and its hierarchy,
- // so we don't bother notifying the FocusManager in that case because it
- // will have already been destroyed (the Widget that contains us is
- // NCDESTROY'ed which in turn destroys the focus manager _before_ the
- // RootView is deleted.)
-#if defined(OS_WIN)
- Window* window = GetWindow();
- if (window) {
- FocusManager* focus_manager =
- FocusManager::GetFocusManager(window->GetNativeWindow());
+ FocusManager* focus_manager = widget_->GetFocusManager();
+ // An unparanted RootView does not have a FocusManager.
+ if (focus_manager)
focus_manager->ViewRemoved(parent, child);
- }
ViewStorage::GetSharedInstance()->ViewRemoved(parent, child);
-#endif
}
}
@@ -521,7 +509,6 @@ void RootView::OnWidgetDestroyed() {
// TODO(port): Port RootViewDropTarget and this goes away.
NOTIMPLEMENTED();
#endif
- widget_ = NULL;
}
void RootView::ProcessMouseDragCanceled() {
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 1dabf08..9c4c5ef 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -17,6 +17,7 @@ class Rect;
namespace views {
class Accelerator;
+class FocusManager;
class RootView;
class TooltipManager;
class Window;
@@ -105,13 +106,17 @@ class Widget {
virtual Window* GetWindow() { return NULL; }
virtual const Window* GetWindow() const { return NULL; }
- // Get the theme provider.
+ // Gets the theme provider.
virtual ThemeProvider* GetThemeProvider() const { return NULL; }
- // Get the default theme provider; this is necessary for when a widget has
+ // Gets the default theme provider; this is necessary for when a widget has
// no profile (and ThemeProvider) associated with it. The default theme
// provider provides a default set of bitmaps that such widgets can use.
virtual ThemeProvider* GetDefaultThemeProvider() { return NULL; }
+
+ // Returns the FocusManager for this widget.
+ // Note that all widgets in a widget hierarchy share the same focus manager.
+ virtual FocusManager* GetFocusManager() { return NULL; }
};
} // namespace views
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 1fe3416..8f280d1 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -154,8 +154,7 @@ WidgetWin::~WidgetWin() {
MessageLoopForUI::current()->RemoveObserver(this);
}
-void WidgetWin::Init(HWND parent, const gfx::Rect& bounds,
- bool has_own_focus_manager) {
+void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) {
if (window_style_ == 0)
window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle;
@@ -187,8 +186,9 @@ void WidgetWin::Init(HWND parent, const gfx::Rect& bounds,
root_view_->OnWidgetCreated();
- if (has_own_focus_manager) {
- FocusManager::CreateFocusManager(hwnd_, GetRootView());
+ if ((window_style_ & WS_CHILD) == 0) {
+ // Top-level widgets get a FocusManager.
+ focus_manager_.reset(new FocusManager(this));
}
// Sets the RootView as a property, so the automation can introspect windows.
@@ -419,6 +419,18 @@ const Window* WidgetWin::GetWindow() const {
return GetWindowImpl(hwnd_);
}
+FocusManager* WidgetWin::GetFocusManager() {
+ if (focus_manager_.get())
+ return focus_manager_.get();
+
+ HWND root = ::GetAncestor(hwnd_, GA_ROOT);
+ if (!root)
+ return NULL;
+
+ WidgetWin* widget = GetWidget(root);
+ return widget ? widget->focus_manager_.get() : NULL;
+}
+
void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) {
if (use_layered_buffer_ == use_layered_buffer)
return;
@@ -460,7 +472,12 @@ RootView* WidgetWin::FindRootView(HWND hwnd) {
return root_view;
}
-///////////////////////////////////////////////////////////////////////////////
+// static
+WidgetWin* WidgetWin::GetWidget(HWND hwnd) {
+ return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd));
+}
+
+////////////////////////////////////////////////////////////////////////////////
// MessageLoop::Observer
void WidgetWin::WillProcessMessage(const MSG& msg) {
@@ -472,7 +489,7 @@ void WidgetWin::DidProcessMessage(const MSG& msg) {
}
}
-///////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
// FocusTraversable
View* WidgetWin::FindNextFocusableView(
@@ -1039,10 +1056,8 @@ LRESULT CALLBACK WidgetWin::WndProc(HWND window, UINT message,
// Otherwise we handle everything else.
if (!widget->ProcessWindowMessage(window, message, w_param, l_param, result))
result = DefWindowProc(window, message, w_param, l_param);
- if (message == WM_NCDESTROY) {
- widget->hwnd_ = NULL;
+ if (message == WM_NCDESTROY)
widget->OnFinalMessage(window);
- }
if (message == WM_ACTIVATE)
PostProcessActivateMessage(widget, LOWORD(w_param));
return result;
@@ -1051,18 +1066,16 @@ LRESULT CALLBACK WidgetWin::WndProc(HWND window, UINT message,
// static
void WidgetWin::PostProcessActivateMessage(WidgetWin* widget,
int activation_state) {
- FocusManager* focus_manager =
- FocusManager::GetFocusManager(widget->GetNativeView());
- if (!focus_manager) {
+ if (!widget->focus_manager_.get()) {
NOTREACHED();
return;
}
if (WA_INACTIVE == activation_state) {
- focus_manager->StoreFocusedView();
+ widget->focus_manager_->StoreFocusedView();
} else {
// We must restore the focus after the message has been DefProc'ed as it
// does set the focus to the last focused HWND.
- focus_manager->RestoreFocusedView();
+ widget->focus_manager_->RestoreFocusedView();
}
}
} // namespace views
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index b8500c7..6ae1141 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -78,11 +78,7 @@ class WidgetWin : public Widget,
// this view, you are responsible for its destruction. If this value is NULL,
// the caller is responsible for populating the RootView, and sizing its
// contents as the window is sized.
- // If |has_own_focus_manager| is true, the focus traversal stay confined to
- // the window.
- void Init(HWND parent,
- const gfx::Rect& bounds,
- bool has_own_focus_manager);
+ void Init(HWND parent, const gfx::Rect& bounds);
// Sets the specified view as the contents of this Widget. There can only
// be one contnets view child of this Widget's RootView. This view is sized to
@@ -122,6 +118,9 @@ class WidgetWin : public Widget,
// Returns the RootView associated with the specified HWND (if any).
static RootView* FindRootView(HWND hwnd);
+ // Returns the Widget associated with the specified HWND (if any).
+ static WidgetWin* GetWidget(HWND hwnd);
+
// All classes registered by WidgetWin start with this name.
static const wchar_t* const kBaseClassName;
@@ -230,6 +229,7 @@ class WidgetWin : public Widget,
virtual ThemeProvider* GetThemeProvider() const;
virtual Window* GetWindow();
virtual const Window* GetWindow() const;
+ virtual FocusManager* GetFocusManager();
// Overridden from MessageLoop::Observer:
void WillProcessMessage(const MSG& msg);
@@ -327,7 +327,6 @@ class WidgetWin : public Widget,
}
protected:
-
// Call close instead of this to Destroy the window.
BOOL DestroyWindow() {
DCHECK(::IsWindow(GetNativeView()));
@@ -523,6 +522,12 @@ class WidgetWin : public Widget,
// the TooltipManager.
scoped_ptr<TooltipManagerWin> tooltip_manager_;
+ // The focus manager keeping track of focus for this Widget and any of its
+ // children. NULL for non top-level widgets.
+ // WARNING: RootView's destructor calls into the FocusManager. As such, this
+ // must be destroyed AFTER root_view_.
+ scoped_ptr<FocusManager> focus_manager_;
+
// The root of the View hierarchy attached to this window.
// WARNING: see warning in tooltip_manager_ for ordering dependencies with
// this and tooltip_manager_.
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index fc809932..9f53ae2 100755
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -513,7 +513,7 @@ void WindowWin::Init(HWND parent, const gfx::Rect& bounds) {
if (window_ex_style() == 0)
set_window_ex_style(CalculateWindowExStyle());
- WidgetWin::Init(parent, bounds, true);
+ WidgetWin::Init(parent, bounds);
win_util::SetWindowUserData(GetNativeView(), this);
// Create the ClientView, add it to the NonClientView and add the