diff options
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/custom_frame_window.cc | 8 | ||||
-rw-r--r-- | chrome/views/window.cc | 112 | ||||
-rw-r--r-- | chrome/views/window.h | 41 |
3 files changed, 79 insertions, 82 deletions
diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc index 28146b6..928947e 100644 --- a/chrome/views/custom_frame_window.cc +++ b/chrome/views/custom_frame_window.cc @@ -866,9 +866,9 @@ void CustomFrameWindow::Init(HWND parent, const gfx::Rect& bounds) { ResetWindowRegion(); } -void CustomFrameWindow::SetClientView(ClientView* client_view) { - DCHECK(client_view && !client_view_ && GetHWND()); - client_view_ = client_view; +void CustomFrameWindow::SetClientView(ClientView* cv) { + DCHECK(cv && !client_view() && GetHWND()); + set_client_view(cv); // 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 @@ -895,7 +895,7 @@ void CustomFrameWindow::EnableClose(bool enable) { void CustomFrameWindow::SizeWindowToDefault() { CSize pref(0, 0); - client_view_->GetPreferredSize(&pref); + client_view()->GetPreferredSize(&pref); DCHECK(pref.cx > 0 && pref.cy > 0); gfx::Size window_size = non_client_view_->CalculateWindowSizeForClientSize(pref.cx, pref.cy); diff --git a/chrome/views/window.cc b/chrome/views/window.cc index 4243994..4ace937 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window.cc @@ -54,27 +54,6 @@ static const int kMonitorEdgePadding = 10; //////////////////////////////////////////////////////////////////////////////// // Window, public: -Window::Window(WindowDelegate* window_delegate) - : HWNDViewContainer(), - focus_on_creation_(true), - window_delegate_(window_delegate), - client_view_(NULL), - owning_hwnd_(NULL), - minimum_size_(100, 100), - is_modal_(false), - restored_enabled_(false), - is_always_on_top_(false), - window_closed_(false) { - InitClass(); - DCHECK(window_delegate_); - window_delegate_->window_.reset(this); - // Initialize these values to 0 so that subclasses can override the default - // behavior before calling Init. - set_window_style(0); - set_window_ex_style(0); - BrowserList::AddDependentWindow(this); -} - Window::~Window() { BrowserList::RemoveDependentWindow(this); } @@ -93,41 +72,6 @@ Window* Window::CreateChromeWindow(HWND parent, return window; } -void Window::Init(HWND parent, const gfx::Rect& bounds) { - // We need to save the parent window, since later calls to GetParent() will - // return NULL. - owning_hwnd_ = parent; - // We call this after initializing our members since our implementations of - // assorted HWNDViewContainer functions may be called during initialization. - is_modal_ = window_delegate_->IsModal(); - if (is_modal_) - BecomeModal(); - is_always_on_top_ = window_delegate_->IsAlwaysOnTop(); - - if (window_style() == 0) - set_window_style(CalculateWindowStyle()); - if (window_ex_style() == 0) - set_window_ex_style(CalculateWindowExStyle()); - - HWNDViewContainer::Init(parent, bounds, true); - win_util::SetWindowUserData(GetHWND(), this); - - std::wstring window_title = window_delegate_->GetWindowTitle(); - SetWindowText(GetHWND(), window_title.c_str()); - - SetClientView(window_delegate_->CreateClientView(this)); - SetInitialBounds(bounds); - - if (window_delegate_->HasAlwaysOnTopMenu()) - AddAlwaysOnTopSystemMenuItem(); -} - -void Window::SetClientView(ClientView* client_view) { - DCHECK(client_view && !client_view_ && GetHWND()); - client_view_ = client_view; - HWNDViewContainer::SetContentsView(client_view_); -} - gfx::Size Window::CalculateWindowSizeForClientSize( const gfx::Size& client_size) const { RECT r = { 0, 0, client_size.width(), client_size.height() }; @@ -303,6 +247,62 @@ gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, /////////////////////////////////////////////////////////////////////////////// // Window, protected: +Window::Window(WindowDelegate* window_delegate) + : HWNDViewContainer(), + focus_on_creation_(true), + window_delegate_(window_delegate), + client_view_(NULL), + owning_hwnd_(NULL), + minimum_size_(100, 100), + is_modal_(false), + restored_enabled_(false), + is_always_on_top_(false), + window_closed_(false) { + InitClass(); + DCHECK(window_delegate_); + window_delegate_->window_.reset(this); + // Initialize these values to 0 so that subclasses can override the default + // behavior before calling Init. + set_window_style(0); + set_window_ex_style(0); + BrowserList::AddDependentWindow(this); +} + +void Window::Init(HWND parent, const gfx::Rect& bounds) { + // We need to save the parent window, since later calls to GetParent() will + // return NULL. + owning_hwnd_ = parent; + // We call this after initializing our members since our implementations of + // assorted HWNDViewContainer functions may be called during initialization. + is_modal_ = window_delegate_->IsModal(); + if (is_modal_) + BecomeModal(); + is_always_on_top_ = window_delegate_->IsAlwaysOnTop(); + + if (window_style() == 0) + set_window_style(CalculateWindowStyle()); + if (window_ex_style() == 0) + set_window_ex_style(CalculateWindowExStyle()); + + HWNDViewContainer::Init(parent, bounds, true); + win_util::SetWindowUserData(GetHWND(), this); + + std::wstring window_title = window_delegate_->GetWindowTitle(); + SetWindowText(GetHWND(), window_title.c_str()); + + SetClientView(window_delegate_->CreateClientView(this)); + SetInitialBounds(bounds); + + if (window_delegate_->HasAlwaysOnTopMenu()) + AddAlwaysOnTopSystemMenuItem(); +} + +void Window::SetClientView(ClientView* client_view) { + DCHECK(client_view && !client_view_ && GetHWND()); + client_view_ = client_view; + HWNDViewContainer::SetContentsView(client_view_); +} + void Window::SizeWindowToDefault() { CSize pref(0, 0); client_view_->GetPreferredSize(&pref); diff --git a/chrome/views/window.h b/chrome/views/window.h index 534634c..a941cb2 100644 --- a/chrome/views/window.h +++ b/chrome/views/window.h @@ -56,14 +56,6 @@ class WindowDelegate; //////////////////////////////////////////////////////////////////////////////// class Window : public HWNDViewContainer { public: - // TODO(beng): (Cleanup) move these into private section, effectively making - // this class "final" to all but designated friends within - // ChromeViews. Users in browser/ should always construct with - // CreateChromeWindow which will give the right version, - // depending on platform & configuration. - // Create a Window using the specified delegate. The delegate must not be - // NULL. - explicit Window(WindowDelegate* window_delegate); virtual ~Window(); // Creates the appropriate Window class for a Chrome dialog or window. This @@ -72,12 +64,6 @@ class Window : public HWNDViewContainer { const gfx::Rect& bounds, WindowDelegate* window_delegate); - // Create the Window. - // If parent is NULL, this Window is top level on the desktop. - // If |bounds| is empty, the view is queried for its preferred size and - // centered on screen. - virtual void Init(HWND parent, const gfx::Rect& bounds); - // Return the size of window (including non-client area) required to contain // a window of the specified client size. virtual gfx::Size CalculateWindowSizeForClientSize( @@ -155,6 +141,15 @@ class Window : public HWNDViewContainer { int row_resource_id); protected: + // Constructs the Window. |window_delegate| cannot be NULL. + explicit Window(WindowDelegate* window_delegate); + + // Create the Window. + // If parent is NULL, this Window is top level on the desktop. + // If |bounds| is empty, the view is queried for its preferred size and + // centered on screen. + virtual void Init(HWND parent, const gfx::Rect& bounds); + // Sets the specified view as the ClientView of this Window. The ClientView // is responsible for laying out the Window's contents view, as well as // performing basic hit-testing, and perhaps other responsibilities depending @@ -167,6 +162,8 @@ class Window : public HWNDViewContainer { // Sizes the window to the default size specified by its ClientView. virtual void SizeWindowToDefault(); + void set_client_view(ClientView* client_view) { client_view_ = client_view; } + // Overridden from HWNDViewContainer: virtual void OnActivate(UINT action, BOOL minimized, HWND window); virtual void OnCommand(UINT notification_code, int command_id, HWND window); @@ -177,14 +174,6 @@ class Window : public HWNDViewContainer { virtual void OnSize(UINT size_param, const CSize& new_size); virtual void OnSysCommand(UINT notification_code, CPoint click); - // A ClientView object or subclass, responsible for sizing the contents view - // of the window, hit testing and perhaps other tasks depending on the - // implementation. - ClientView* client_view_; - - // Our window delegate (see Init method for documentation). - WindowDelegate* window_delegate_; - private: // Set the window as modal (by disabling all the other windows). void BecomeModal(); @@ -218,6 +207,14 @@ class Window : public HWNDViewContainer { static void InitClass(); static HCURSOR nwse_cursor_; + // A ClientView object or subclass, responsible for sizing the contents view + // of the window, hit testing and perhaps other tasks depending on the + // implementation. + ClientView* client_view_; + + // Our window delegate (see Init method for documentation). + WindowDelegate* window_delegate_; + // Whether we should SetFocus() on a newly created window after // Init(). Defaults to true. bool focus_on_creation_; |