diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 05:43:17 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-30 05:43:17 +0000 |
commit | a8da3a55ce6358c92cc976f105567f67789a2510 (patch) | |
tree | 26f58f20a9ab36ffe2cc8d563edacec5dfc7d3dd /chrome/views | |
parent | f73bdc8c33f0b395ba058083505209baeedf9f38 (diff) | |
download | chromium_src-a8da3a55ce6358c92cc976f105567f67789a2510.zip chromium_src-a8da3a55ce6358c92cc976f105567f67789a2510.tar.gz chromium_src-a8da3a55ce6358c92cc976f105567f67789a2510.tar.bz2 |
Make HWNDViewContainer set up its contents view separately from its Init method.
This is needed as a first step in further adjustments I'm going to be making to
Window, ClientView, etc.
B=1280060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/chrome_menu.cc | 3 | ||||
-rw-r--r-- | chrome/views/focus_manager_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/views/hwnd_view_container.cc | 30 | ||||
-rw-r--r-- | chrome/views/hwnd_view_container.h | 7 | ||||
-rw-r--r-- | chrome/views/tabbed_pane.cc | 2 | ||||
-rw-r--r-- | chrome/views/view_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/views/window.cc | 10 |
7 files changed, 33 insertions, 26 deletions
diff --git a/chrome/views/chrome_menu.cc b/chrome/views/chrome_menu.cc index 9bb8c76..72fdf1b 100644 --- a/chrome/views/chrome_menu.cc +++ b/chrome/views/chrome_menu.cc @@ -678,7 +678,8 @@ class MenuHost : public HWNDViewContainer { const gfx::Rect& bounds, View* contents_view, bool do_capture) { - HWNDViewContainer::Init(parent, bounds, contents_view, true); + HWNDViewContainer::Init(parent, bounds, true); + SetContentsView(contents_view); // We don't want to take focus away from the hosting window. ShowWindow(SW_SHOWNA); owns_capture_ = do_capture; diff --git a/chrome/views/focus_manager_unittest.cc b/chrome/views/focus_manager_unittest.cc index ed5127e..4a7240a 100644 --- a/chrome/views/focus_manager_unittest.cc +++ b/chrome/views/focus_manager_unittest.cc @@ -141,7 +141,8 @@ class BorderView : public ChromeViews::NativeControl { parent_container, NULL, NULL, NULL); // Create the view container which is a child of the TabControl. view_container_ = new ChromeViews::HWNDViewContainer(); - view_container_->Init(tab_control, gfx::Rect(), child_, false); + view_container_->Init(tab_control, gfx::Rect(), false); + view_container_->SetContentsView(child_); view_container_->SetFocusTraversableParentView(this); ResizeContents(tab_control); return tab_control; diff --git a/chrome/views/hwnd_view_container.cc b/chrome/views/hwnd_view_container.cc index 6aa2332..69545c9 100644 --- a/chrome/views/hwnd_view_container.cc +++ b/chrome/views/hwnd_view_container.cc @@ -169,7 +169,6 @@ HWNDViewContainer::~HWNDViewContainer() { void HWNDViewContainer::Init(HWND parent, const gfx::Rect& bounds, - View* contents_view, bool has_own_focus_manager) { toplevel_ = parent == NULL; @@ -207,20 +206,6 @@ void HWNDViewContainer::Init(HWND parent, FocusManager::InstallFocusSubclass(hwnd_, NULL); } - // The RootView is set up _after_ the window is created so that its - // ViewContainer pointer is valid. - if (contents_view) { - // The FillLayout only applies when we have been provided with a single - // contents view. If the user intends to manage the RootView themselves, - // they are responsible for providing their own LayoutManager, since - // FillLayout is only capable of laying out a single child view. - root_view_->SetLayoutManager(new FillLayout()); - root_view_->AddChildView(contents_view); - } - - // Manually size the window here to ensure the root view is laid out. - ChangeSize(0, CSize(bounds.width(), bounds.height())); - // Sets the RootView as a property, so the automation can introspect windows. SetRootViewForHWND(hwnd_, root_view_.get()); @@ -247,6 +232,21 @@ void HWNDViewContainer::Init(HWND parent, ::ImmAssociateContextEx(GetHWND(), NULL, 0); } +void HWNDViewContainer::SetContentsView(View* view) { + DCHECK(view && hwnd_) << "Can't be called until after the HWND is created!"; + // The ContentsView must be set up _after_ the window is created so that its + // ViewContainer pointer is valid. + root_view_->SetLayoutManager(new FillLayout); + if (root_view_->GetChildViewCount() != 0) + root_view_->RemoveAllChildViews(true); + root_view_->AddChildView(view); + + // Manually size the window here to ensure the root view is laid out. + RECT wr; + GetWindowRect(&wr); + ChangeSize(0, CSize(wr.right - wr.left, wr.bottom - wr.top)); +} + /////////////////////////////////////////////////////////////////////////////// // ChromeViews::ViewContainer diff --git a/chrome/views/hwnd_view_container.h b/chrome/views/hwnd_view_container.h index a8fd689..c9ceb12 100644 --- a/chrome/views/hwnd_view_container.h +++ b/chrome/views/hwnd_view_container.h @@ -112,9 +112,14 @@ class HWNDViewContainer : public ViewContainer, // the window. void Init(HWND parent, const gfx::Rect& bounds, - View* contents_view, bool has_own_focus_manager); + // Sets the specified view as the contents of this HWNDViewContainer. There + // can only be one contnets view child of this ViewContainer's RootView. This + // view is sized to fit the entire size of the RootView. The RootView takes + // ownership of this View, unless it is set as not being parent-owned. + virtual void SetContentsView(View* view); + // Sets the window styles. This is ONLY used when the window is created. // In other words, if you invoke this after invoking Init, nothing happens. void set_window_style(DWORD style) { window_style_ = style; } diff --git a/chrome/views/tabbed_pane.cc b/chrome/views/tabbed_pane.cc index 8ca6155..5d9677a 100644 --- a/chrome/views/tabbed_pane.cc +++ b/chrome/views/tabbed_pane.cc @@ -189,7 +189,7 @@ HWND TabbedPane::CreateNativeControl(HWND parent_container) { // Create the view container which is a child of the TabControl. content_window_ = new HWNDViewContainer(); - content_window_->Init(tab_control_, gfx::Rect(), NULL, false); + content_window_->Init(tab_control_, gfx::Rect(), false); // 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/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc index 44de0c0..3dfd986 100644 --- a/chrome/views/view_unittest.cc +++ b/chrome/views/view_unittest.cc @@ -383,10 +383,10 @@ TEST_F(ViewTest, Painting) { RDW_UPDATENOW | RDW_INVALIDATE | RDW_ALLCHILDREN); bool empty_paint = paint_window.empty_paint(); - ChromeViews::Window window; + ChromeViews::HWNDViewContainer window; window.set_delete_on_destroy(false); window.set_window_style(WS_OVERLAPPEDWINDOW); - window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL, NULL); + window.Init(NULL, gfx::Rect(50, 50, 650, 650), NULL); RootView* root = window.GetRootView(); TestView* v1 = new TestView(); diff --git a/chrome/views/window.cc b/chrome/views/window.cc index b02afcb..042968b 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window.cc @@ -116,18 +116,18 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) { // associated with the root of the window tree... if (use_client_view_) { View* contents_view = window_delegate_->GetContentsView(); - if (!contents_view) - contents_view = new View; + DCHECK(contents_view); client_view_ = new ClientView(this, contents_view); // A Window almost always owns its own focus manager, even if it's a child // window. File a bug if you find a circumstance where this isn't the case // and we can adjust this API. Note that if this is not the case, you'll // also have to change SetInitialFocus() as it relies on the window's focus // manager. - HWNDViewContainer::Init(parent, bounds, client_view_, true); + HWNDViewContainer::Init(parent, bounds, true); + SetContentsView(client_view_); } else { - HWNDViewContainer::Init(parent, bounds, - window_delegate_->GetContentsView(), true); + HWNDViewContainer::Init(parent, bounds, true); + SetContentsView(window_delegate_->GetContentsView()); } win_util::SetWindowUserData(GetHWND(), this); |