diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 00:42:17 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-07-31 00:42:17 +0000 |
commit | b2a4b9f96997dc3b929b5b9930325a030a8294e3 (patch) | |
tree | 3b18dd4002b9f6b681dd8256783f9d308591568f /chrome/views/custom_frame_window.cc | |
parent | cd5241ff75071da8e4345e81ebc220e17505a306 (diff) | |
download | chromium_src-b2a4b9f96997dc3b929b5b9930325a030a8294e3.zip chromium_src-b2a4b9f96997dc3b929b5b9930325a030a8294e3.tar.gz chromium_src-b2a4b9f96997dc3b929b5b9930325a030a8294e3.tar.bz2 |
Move dialog-specific aspects of ClientView into a new subclass DialogClientView.
ClientView becomes a generic representation of the View that occupies the "client area" of a window. All Windows now require a Client View (though they can use the default).
Adjust WindowDelegate to provide a method for constructing the ClientView for a Window. The DialogDelegate overrides this to construct the DialogClientView. In the future, other specialized delegates will construct ClientViews specific to them, e.g. WizardDelegate would construct WizardClientView.
Adjust the Window Init method to set up this new required Client View, and make some tweaks to CustomFrameWindow to make all this work.
Remove all traces of dialog specific handling in Window into DialogClientView.
B=1280060
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/custom_frame_window.cc')
-rw-r--r-- | chrome/views/custom_frame_window.cc | 105 |
1 files changed, 51 insertions, 54 deletions
diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc index 8c6bf98..28146b6 100644 --- a/chrome/views/custom_frame_window.cc +++ b/chrome/views/custom_frame_window.cc @@ -49,7 +49,7 @@ namespace ChromeViews { HCURSOR CustomFrameWindow::resize_cursors_[6]; -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // WindowResources // // An enumeration of bitmap resources used by this window. @@ -222,7 +222,7 @@ SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; ChromeFont InactiveWindowResources::title_font_; -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // // DefaultNonClientView // @@ -237,7 +237,6 @@ class DefaultNonClientView : public NonClientView, virtual ~DefaultNonClientView(); // Overridden from CustomFrameWindow::NonClientView: - virtual void Init(ClientView* client_view); virtual gfx::Rect CalculateClientAreaBounds(int width, int height) const; virtual gfx::Size CalculateWindowSizeForClientSize(int width, int height) const; @@ -250,6 +249,7 @@ class DefaultNonClientView : public NonClientView, virtual void Paint(ChromeCanvas* canvas); virtual void Layout(); virtual void GetPreferredSize(CSize* out); + virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); // BaseButton::ButtonListener implementation: virtual void ButtonPressed(BaseButton* sender); @@ -327,7 +327,7 @@ static const int kResizeAreaCornerSize = 16; static const int kWindowHorizontalBorderSize = 4; static const int kWindowVerticalBorderSize = 4; -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // DefaultNonClientView, public: DefaultNonClientView::DefaultNonClientView( @@ -385,19 +385,9 @@ DefaultNonClientView::DefaultNonClientView( DefaultNonClientView::~DefaultNonClientView() { } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // DefaultNonClientView, CustomFrameWindow::NonClientView implementation: -void DefaultNonClientView::Init(ClientView* client_view) { - client_view_ = client_view; - AddChildView(client_view_); - // TODO(beng): (Cleanup) this should mostly move down to Window, because - // it'll be needed for that version too, but with a virtual - // override here to update the NC view. - SetWindowIcon(container_->window_delegate()->GetWindowIcon()); -} - - gfx::Rect DefaultNonClientView::CalculateClientAreaBounds( int width, int height) const { int top_margin = CalculateContentsTop(); @@ -440,15 +430,9 @@ int DefaultNonClientView::NonClientHitTest(const gfx::Point& point) { // First see if it's within the grow box area, since that overlaps the client // bounds. - if (client_view_->PointIsInSizeBox(point)) - return HTBOTTOMRIGHT; - - // Then see if it's within the client area. - if (client_view_) { - client_view_->GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION); - if (bounds.PtInRect(test_point)) - return HTCLIENT; - } + int component = container_->client_view()->NonClientHitTest(point); + if (component != HTNOWHERE) + return component; // Then see if the point is within any of the window controls. close_button_->GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION); @@ -467,7 +451,7 @@ int DefaultNonClientView::NonClientHitTest(const gfx::Point& point) { if (bounds.PtInRect(test_point)) return HTSYSMENU; - int component = GetHTComponentForFrame( + component = GetHTComponentForFrame( point, kResizeAreaSize, kResizeAreaCornerSize, @@ -507,7 +491,7 @@ void DefaultNonClientView::EnableClose(bool enable) { close_button_->SetEnabled(enable); } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // DefaultNonClientView, View overrides: void DefaultNonClientView::Paint(ChromeCanvas* canvas) { @@ -537,14 +521,21 @@ void DefaultNonClientView::Layout() { void DefaultNonClientView::GetPreferredSize(CSize* out) { DCHECK(out); - if (client_view_) { - client_view_->GetPreferredSize(out); - out->cx += 2 * kWindowHorizontalBorderSize; - out->cy += CalculateContentsTop() + kWindowVerticalBorderSize; - } + container_->client_view()->GetPreferredSize(out); + out->cx += 2 * kWindowHorizontalBorderSize; + out->cy += CalculateContentsTop() + kWindowVerticalBorderSize; } -//////////////////////////////////////////////////////////////////////////////// +void DefaultNonClientView::ViewHierarchyChanged(bool is_add, + View* parent, + View* child) { + // Add our Client View as we are added to the ViewContainer so that if we are + // subsequently resized all the parent-child relationships are established. + if (is_add && GetViewContainer() && child == this) + AddChildView(container_->client_view()); +} + +/////////////////////////////////////////////////////////////////////////////// // DefaultNonClientView, BaseButton::ButtonListener implementation: void DefaultNonClientView::ButtonPressed(BaseButton* sender) { @@ -559,7 +550,7 @@ void DefaultNonClientView::ButtonPressed(BaseButton* sender) { } } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // DefaultNonClientView, private: void DefaultNonClientView::SetWindowIcon(SkBitmap window_icon) { @@ -650,7 +641,7 @@ void DefaultNonClientView::PaintClientEdge(ChromeCanvas* canvas) { SkBitmap* left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT); CRect client_area_bounds; - client_view_->GetBounds(&client_area_bounds); + container_->client_view()->GetBounds(&client_area_bounds); canvas->DrawBitmapInt(*top_left, client_area_bounds.left - top_left->width(), client_area_bounds.top - top->height()); @@ -822,11 +813,9 @@ void DefaultNonClientView::LayoutTitleBar() { } void DefaultNonClientView::LayoutClientView() { - if (client_view_) { - gfx::Rect client_bounds( - CalculateClientAreaBounds(GetWidth(), GetHeight())); - client_view_->SetBounds(client_bounds.ToRECT()); - } + gfx::Rect client_bounds( + CalculateClientAreaBounds(GetWidth(), GetHeight())); + container_->client_view()->SetBounds(client_bounds.ToRECT()); } // static @@ -839,7 +828,7 @@ void DefaultNonClientView::InitClass() { } } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // CustomFrameWindow, public: CustomFrameWindow::CustomFrameWindow(WindowDelegate* window_delegate) @@ -859,25 +848,33 @@ CustomFrameWindow::CustomFrameWindow(WindowDelegate* window_delegate, CustomFrameWindow::~CustomFrameWindow() { } -void CustomFrameWindow::Init(HWND owner, const gfx::Rect& bounds) { - Window::Init(owner, bounds); - // We need to re-parent the client view to the non-client view. - GetRootView()->RemoveChildView(client_view_); - GetRootView()->AddChildView(non_client_view_); - non_client_view_->Init(client_view_); - GetRootView()->Layout(); - - ResetWindowRegion(); -} - void CustomFrameWindow::ExecuteSystemMenuCommand(int command) { if (command) SendMessage(GetHWND(), WM_SYSCOMMAND, command, 0); } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // CustomFrameWindow, Window overrides: +void CustomFrameWindow::Init(HWND parent, const gfx::Rect& bounds) { + // TODO(beng): (Cleanup) Right now, the only way to specify a different + // non-client view is to subclass this object and provide one + // by setting this member before calling Init. + if (!non_client_view_) + non_client_view_ = new DefaultNonClientView(this); + Window::Init(parent, bounds); + ResetWindowRegion(); +} + +void CustomFrameWindow::SetClientView(ClientView* client_view) { + DCHECK(client_view && !client_view_ && GetHWND()); + client_view_ = client_view; + // For a CustomFrameWindow, the non-client view is the root. + HWNDViewContainer::SetContentsView(non_client_view_); + // When the non client view is added to the view hierarchy, it will cause the + // client view to be added as well. +} + gfx::Size CustomFrameWindow::CalculateWindowSizeForClientSize( const gfx::Size& client_size) const { return non_client_view_->CalculateWindowSizeForClientSize( @@ -906,7 +903,7 @@ void CustomFrameWindow::SizeWindowToDefault() { window_size.ToSIZE(), false); } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // CustomFrameWindow, HWNDViewContainer overrides: static void EnableMenuItem(HMENU menu, UINT command, bool enabled) { @@ -1161,7 +1158,7 @@ void CustomFrameWindow::OnSize(UINT param, const CSize& size) { ResetWindowRegion(); } -//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// // CustomFrameWindow, private: void CustomFrameWindow::RunSystemMenu(const CPoint& point) { |