summaryrefslogtreecommitdiffstats
path: root/chrome/views/window.cc
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-31 00:42:17 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-31 00:42:17 +0000
commitb2a4b9f96997dc3b929b5b9930325a030a8294e3 (patch)
tree3b18dd4002b9f6b681dd8256783f9d308591568f /chrome/views/window.cc
parentcd5241ff75071da8e4345e81ebc220e17505a306 (diff)
downloadchromium_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/window.cc')
-rw-r--r--chrome/views/window.cc103
1 files changed, 23 insertions, 80 deletions
diff --git a/chrome/views/window.cc b/chrome/views/window.cc
index 042968b..4243994 100644
--- a/chrome/views/window.cc
+++ b/chrome/views/window.cc
@@ -36,7 +36,6 @@
#include "chrome/common/pref_service.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
-#include "chrome/views/client_view.h"
#include "chrome/views/custom_frame_window.h"
#include "chrome/views/window_delegate.h"
@@ -65,8 +64,6 @@ Window::Window(WindowDelegate* window_delegate)
is_modal_(false),
restored_enabled_(false),
is_always_on_top_(false),
- use_client_view_(true),
- accepted_(false),
window_closed_(false) {
InitClass();
DCHECK(window_delegate_);
@@ -112,33 +109,25 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) {
if (window_ex_style() == 0)
set_window_ex_style(CalculateWindowExStyle());
- // A child window never owns its own focus manager, it uses the one
- // associated with the root of the window tree...
- if (use_client_view_) {
- View* contents_view = window_delegate_->GetContentsView();
- 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, true);
- SetContentsView(client_view_);
- } else {
- HWNDViewContainer::Init(parent, bounds, true);
- SetContentsView(window_delegate_->GetContentsView());
- }
+ 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() };
@@ -197,24 +186,7 @@ void Window::Close() {
return;
}
- bool can_close = true;
- // Ask the delegate if we're allowed to close. The user may not have left the
- // window in a state where this is allowable (e.g. unsaved work). Also, don't
- // call Cancel on the delegate if we've already been accepted and are in the
- // process of being closed. Furthermore, if we have only an OK button, but no
- // Cancel button, and we're closing without being accepted, call Accept to
- // see if we should close.
- if (!accepted_) {
- DialogDelegate* dd = window_delegate_->AsDialogDelegate();
- if (dd) {
- int buttons = dd->GetDialogButtons();
- if (buttons & DialogDelegate::DIALOGBUTTON_CANCEL)
- can_close = dd->Cancel();
- else if (buttons & DialogDelegate::DIALOGBUTTON_OK)
- can_close = dd->Accept(true);
- }
- }
- if (can_close) {
+ if (client_view_->CanClose()) {
SaveWindowPosition();
RestoreEnabledIfNecessary();
HWNDViewContainer::Close();
@@ -256,27 +228,6 @@ void Window::EnableClose(bool enable) {
SWP_NOZORDER);
}
-void Window::UpdateDialogButtons() {
- if (client_view_)
- client_view_->UpdateDialogButtons();
-}
-
-void Window::AcceptWindow() {
- accepted_ = true;
- DialogDelegate* dd = window_delegate_->AsDialogDelegate();
- if (dd)
- accepted_ = dd->Accept(false);
- if (accepted_)
- Close();
-}
-
-void Window::CancelWindow() {
- // Call the standard Close handler, which checks with the delegate before
- // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler,
- // so that the close box on the window also shares this code path.
- Close();
-}
-
void Window::UpdateWindowTitle() {
std::wstring window_title = window_delegate_->GetWindowTitle();
SetWindowText(GetHWND(), window_title.c_str());
@@ -349,21 +300,19 @@ gfx::Size Window::GetLocalizedContentsSize(int col_resource_id,
return gfx::Size(width, height);
}
-////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
// Window, protected:
void Window::SizeWindowToDefault() {
- if (client_view_) {
- CSize pref(0, 0);
- client_view_->GetPreferredSize(&pref);
- DCHECK(pref.cx > 0 && pref.cy > 0);
- // CenterAndSizeWindow adjusts the window size to accommodate the non-client
- // area.
- win_util::CenterAndSizeWindow(owning_window(), GetHWND(), pref, true);
- }
+ CSize pref(0, 0);
+ client_view_->GetPreferredSize(&pref);
+ DCHECK(pref.cx > 0 && pref.cy > 0);
+ // CenterAndSizeWindow adjusts the window size to accommodate the non-client
+ // area.
+ win_util::CenterAndSizeWindow(owning_window(), GetHWND(), pref, true);
}
-////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
// Window, HWNDViewContainer overrides:
void Window::OnActivate(UINT action, BOOL minimized, HWND window) {
@@ -390,12 +339,13 @@ LRESULT Window::OnEraseBkgnd(HDC dc) {
}
LRESULT Window::OnNCHitTest(const CPoint& point) {
- // We paint the size box over the content area sometimes... check to see if
- // the mouse is over it...
+ // First, give the ClientView a chance to test the point to see if it is part
+ // of the non-client area.
CPoint temp = point;
MapWindowPoints(HWND_DESKTOP, GetHWND(), &temp, 1);
- if (client_view_ && client_view_->PointIsInSizeBox(gfx::Point(temp)))
- return HTBOTTOMRIGHT;
+ int component = client_view_->NonClientHitTest(gfx::Point(temp));
+ if (component != HTNOWHERE)
+ return component;
// Otherwise, we let Windows do all the native frame non-client handling for
// us.
@@ -472,13 +422,6 @@ void Window::SetInitialFocus() {
bool focus_set = false;
ChromeViews::View* v = window_delegate_->GetInitiallyFocusedView();
- // For dialogs, try to focus either the OK or Cancel buttons if any.
- if (!v && window_delegate_->AsDialogDelegate() && client_view_) {
- if (client_view_->ok_button())
- v = client_view_->ok_button();
- else if (client_view_->cancel_button())
- v = client_view_->cancel_button();
- }
if (v) {
focus_set = true;
// In order to make that view the initially focused one, we make it the