diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-14 02:49:59 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-14 02:49:59 +0000 |
commit | 6b33e4da472b3c474a3f1328fdba4a84d4a91886 (patch) | |
tree | 60b1bdfdba96c65bfa671e98d7c4c2392f49593f | |
parent | d0769df5d494568b24f77a54409ec8539bba4cf3 (diff) | |
download | chromium_src-6b33e4da472b3c474a3f1328fdba4a84d4a91886.zip chromium_src-6b33e4da472b3c474a3f1328fdba4a84d4a91886.tar.gz chromium_src-6b33e4da472b3c474a3f1328fdba4a84d4a91886.tar.bz2 |
Rename Window->WindowWin
Pull basic Window interface out of WindowWin into new interface, Window.
Convert code to use it.
Review URL: http://codereview.chromium.org/42201
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11695 0039d316-1c4b-4281-b951-d872f2087c98
44 files changed, 665 insertions, 564 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 5fa08ef..ca473d6 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -1203,7 +1203,7 @@ void AutomationProvider::ClickAppModalDialogButton(int button, bool* success) { if (dialog_delegate && (dialog_delegate->GetDialogButtons() & button) == button) { views::DialogClientView* client_view = - dialog_delegate->window()->client_view()->AsDialogClientView(); + dialog_delegate->window()->GetClientView()->AsDialogClientView(); if ((button & views::DialogDelegate::DIALOGBUTTON_OK) == views::DialogDelegate::DIALOGBUTTON_OK) { client_view->AcceptWindow(); diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index cacb30c..d8f578d 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -23,6 +23,7 @@ #include "chrome/views/link.h" #include "chrome/views/menu.h" #include "chrome/views/native_button.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -965,7 +966,7 @@ TaskManager::~TaskManager() { void TaskManager::Open() { TaskManager* task_manager = GetInstance(); if (task_manager->window()) { - task_manager->window()->MoveToFront(true); + task_manager->window()->Activate(); } else { views::Window::CreateChromeWindow(NULL, gfx::Rect(), task_manager); task_manager->table_model_->StartUpdating(); diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index 91c10e0..c997c1d 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -784,7 +784,7 @@ void AboutChromeView::UpdateStatus(GoogleUpdateUpgradeResult result, new_version_available_); update_label_.SetText(update_string); show_success_indicator = true; - RestartMessageBox::ShowMessageBox(window()->GetNativeView()); + RestartMessageBox::ShowMessageBox(window()->GetNativeWindow()); break; } case UPGRADE_ERROR: diff --git a/chrome/browser/views/about_ipc_dialog.cc b/chrome/browser/views/about_ipc_dialog.cc index 673661d..6e9848c 100644 --- a/chrome/browser/views/about_ipc_dialog.cc +++ b/chrome/browser/views/about_ipc_dialog.cc @@ -26,6 +26,7 @@ #include "chrome/common/render_messages.h" #include "chrome/views/grid_layout.h" #include "chrome/views/text_button.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_job.h" diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index 6810d63..8b803bb 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -16,6 +16,7 @@ #include "chrome/views/focus_manager.h" #include "chrome/views/grid_layout.h" #include "chrome/views/label.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "googleurl/src/gurl.h" #include "grit/chromium_strings.h" diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc index fb868c2..a0de947 100644 --- a/chrome/browser/views/bookmark_manager_view.cc +++ b/chrome/browser/views/bookmark_manager_view.cc @@ -30,6 +30,7 @@ #include "chrome/views/label.h" #include "chrome/views/menu_button.h" #include "chrome/views/single_split_view.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index 3d0869a..8ffd4e0 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -368,7 +368,7 @@ int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) { if (!bounds().Contains(point)) return HTNOWHERE; - int frame_component = container_->client_view()->NonClientHitTest(point); + int frame_component = container_->GetClientView()->NonClientHitTest(point); if (frame_component != HTNOWHERE) return frame_component; @@ -378,7 +378,7 @@ int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, - container_->window_delegate()->CanResize()); + container_->GetDelegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -606,10 +606,6 @@ views::NonClientFrameView* ConstrainedWindowImpl::CreateFrameViewForWindow() { return new ConstrainedWindowFrameView(this); } -void ConstrainedWindowImpl::UpdateWindowTitle() { - UpdateUI(TabContents::INVALIDATE_TITLE); -} - 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); @@ -653,8 +649,8 @@ void ConstrainedWindowImpl::DidBecomeSelected() { std::wstring ConstrainedWindowImpl::GetWindowTitle() const { std::wstring display_title; - if (window_delegate()) - display_title = window_delegate()->GetWindowTitle(); + if (GetDelegate()) + display_title = GetDelegate()->GetWindowTitle(); else display_title = L"Untitled"; @@ -671,9 +667,9 @@ const gfx::Rect& ConstrainedWindowImpl::GetCurrentBounds() const { ConstrainedWindowImpl::ConstrainedWindowImpl( TabContents* owner, views::WindowDelegate* window_delegate) - : Window(window_delegate), + : WindowWin(window_delegate), owner_(owner) { - non_client_view_->SetFrameView(CreateFrameViewForWindow()); + GetNonClientView()->SetFrameView(CreateFrameViewForWindow()); Init(); } @@ -685,7 +681,7 @@ void ConstrainedWindowImpl::Init() { } void ConstrainedWindowImpl::InitAsDialog(const gfx::Rect& initial_bounds) { - Window::Init(owner_->GetNativeView(), initial_bounds); + WindowWin::Init(owner_->GetNativeView(), initial_bounds); ActivateConstrainedWindow(); } @@ -719,7 +715,7 @@ void ConstrainedWindowImpl::OnDestroy() { } // Make sure we call super so that it can do its cleanup. - Window::OnDestroy(); + WindowWin::OnDestroy(); } void ConstrainedWindowImpl::OnFinalMessage(HWND window) { @@ -727,7 +723,7 @@ void ConstrainedWindowImpl::OnFinalMessage(HWND window) { // list. owner_->WillClose(this); - WidgetWin::OnFinalMessage(window); + WindowWin::OnFinalMessage(window); } LRESULT ConstrainedWindowImpl::OnMouseActivate(HWND window, diff --git a/chrome/browser/views/constrained_window_impl.h b/chrome/browser/views/constrained_window_impl.h index 30e6303..0fb6763 100644 --- a/chrome/browser/views/constrained_window_impl.h +++ b/chrome/browser/views/constrained_window_impl.h @@ -8,7 +8,7 @@ #include "base/gfx/rect.h" #include "chrome/browser/tab_contents/constrained_window.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" -#include "chrome/views/window.h" +#include "chrome/views/window_win.h" class ConstrainedTabContentsWindowDelegate; class ConstrainedWindowAnimation; @@ -25,7 +25,7 @@ class WindowDelegate; // a child HWND with a custom window frame. // class ConstrainedWindowImpl : public ConstrainedWindow, - public views::Window { + public views::WindowWin { public: virtual ~ConstrainedWindowImpl(); @@ -34,7 +34,6 @@ class ConstrainedWindowImpl : public ConstrainedWindow, // Overridden from views::Window: virtual views::NonClientFrameView* CreateFrameViewForWindow(); - virtual void UpdateWindowTitle(); // Overridden from ConstrainedWindow: virtual void CloseConstrainedWindow(); diff --git a/chrome/browser/views/first_run_customize_view.cc b/chrome/browser/views/first_run_customize_view.cc index 1f8e132..e9ad65e 100644 --- a/chrome/browser/views/first_run_customize_view.cc +++ b/chrome/browser/views/first_run_customize_view.cc @@ -201,7 +201,7 @@ bool FirstRunCustomizeView::Accept() { int browser_selected = import_from_combo_->GetSelectedItem(); FirstRun::ImportSettings(profile_, browser_selected, GetDefaultImportItems(), - window()->GetNativeView()); + window()->GetNativeWindow()); } if (default_browser_->IsSelected()) SetDefaultBrowser(); diff --git a/chrome/browser/views/first_run_view.cc b/chrome/browser/views/first_run_view.cc index 13a10a1..f2df7be 100644 --- a/chrome/browser/views/first_run_view.cc +++ b/chrome/browser/views/first_run_view.cc @@ -150,7 +150,7 @@ void FirstRunView::Layout() { void FirstRunView::OpenCustomizeDialog() { // The customize dialog now owns the importer host object. views::Window::CreateChromeWindow( - window()->GetNativeView(), + window()->GetNativeWindow(), gfx::Rect(), new FirstRunCustomizeView(profile_, importer_host_, @@ -182,7 +182,7 @@ bool FirstRunView::Accept() { SetDefaultBrowser(); // Index 0 is the default browser. FirstRun::ImportSettings(profile_, 0, GetDefaultImportItems(), - window()->GetNativeView()); + window()->GetNativeWindow()); UserMetrics::RecordAction(L"FirstRunDef_Accept", profile_); return true; diff --git a/chrome/browser/views/frame/browser_frame.cc b/chrome/browser/views/frame/browser_frame.cc index 31bf41d..10003af 100644 --- a/chrome/browser/views/frame/browser_frame.cc +++ b/chrome/browser/views/frame/browser_frame.cc @@ -24,11 +24,11 @@ static const int kClientEdgeThickness = 3; // BrowserFrame, public: BrowserFrame::BrowserFrame(BrowserView* browser_view) - : Window(browser_view), + : WindowWin(browser_view), browser_view_(browser_view), frame_initialized_(false) { browser_view_->set_frame(this); - non_client_view_->SetFrameView(CreateFrameViewForWindow()); + GetNonClientView()->SetFrameView(CreateFrameViewForWindow()); // Don't focus anything on creation, selecting a tab will set the focus. set_focus_on_creation(false); } @@ -37,7 +37,7 @@ BrowserFrame::~BrowserFrame() { } void BrowserFrame::Init() { - Window::Init(NULL, gfx::Rect()); + WindowWin::Init(NULL, gfx::Rect()); } int BrowserFrame::GetMinimizeButtonOffset() const { @@ -104,7 +104,7 @@ LRESULT BrowserFrame::OnNCActivate(BOOL active) { // Perform first time initialization of the DWM frame insets, only if we're // using the native frame. - if (non_client_view_->UseNativeFrame() && !frame_initialized_) { + if (GetNonClientView()->UseNativeFrame() && !frame_initialized_) { if (browser_view_->IsBrowserTypeNormal()) { ::SetWindowPos(GetNativeView(), NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED); @@ -113,15 +113,15 @@ LRESULT BrowserFrame::OnNCActivate(BOOL active) { frame_initialized_ = true; } browser_view_->ActivationChanged(!!active); - return Window::OnNCActivate(active); + return WindowWin::OnNCActivate(active); } LRESULT BrowserFrame::OnNCCalcSize(BOOL mode, LPARAM l_param) { // We don't adjust the client area unless we're a tabbed browser window and // are using the native frame. - if (!non_client_view_->UseNativeFrame() || + if (!GetNonClientView()->UseNativeFrame() || !browser_view_->IsBrowserTypeNormal()) { - return Window::OnNCCalcSize(mode, l_param); + return WindowWin::OnNCCalcSize(mode, l_param); } RECT* client_rect = mode ? @@ -173,14 +173,14 @@ LRESULT BrowserFrame::OnNCCalcSize(BOOL mode, LPARAM l_param) { LRESULT BrowserFrame::OnNCHitTest(const CPoint& pt) { // Only do DWM hit-testing when we are using the native frame. - if (non_client_view_->UseNativeFrame()) { + if (GetNonClientView()->UseNativeFrame()) { LRESULT result; if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y), &result)) { return result; } } - return Window::OnNCHitTest(pt); + return WindowWin::OnNCHitTest(pt); } /////////////////////////////////////////////////////////////////////////////// @@ -191,7 +191,7 @@ int BrowserFrame::GetShowState() const { } views::NonClientFrameView* BrowserFrame::CreateFrameViewForWindow() { - if (non_client_view_->UseNativeFrame()) + if (GetNonClientView()->UseNativeFrame()) browser_frame_view_ = new GlassBrowserFrameView(this, browser_view_); else browser_frame_view_ = new OpaqueBrowserFrameView(this, browser_view_); @@ -199,7 +199,7 @@ views::NonClientFrameView* BrowserFrame::CreateFrameViewForWindow() { } void BrowserFrame::UpdateFrameAfterFrameChange() { - Window::UpdateFrameAfterFrameChange(); + WindowWin::UpdateFrameAfterFrameChange(); UpdateDWMFrame(); } @@ -213,7 +213,7 @@ views::RootView* BrowserFrame::CreateRootView() { void BrowserFrame::UpdateDWMFrame() { // Nothing to do yet. - if (!client_view() || !browser_view_->IsBrowserTypeNormal()) + if (!GetClientView() || !browser_view_->IsBrowserTypeNormal()) return; // In fullscreen mode, we don't extend glass into the client area at all, diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h index 7414719..94d099b 100644 --- a/chrome/browser/views/frame/browser_frame.h +++ b/chrome/browser/views/frame/browser_frame.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_ #define CHROME_BROWSER_VIEWS_FRAME_BROWSER_FRAME_ -#include "chrome/views/window.h" +#include "chrome/views/window_win.h" class AeroGlassNonClientView; class BrowserView; @@ -29,10 +29,10 @@ class BrowserNonClientFrameView : public views::NonClientFrameView { /////////////////////////////////////////////////////////////////////////////// // BrowserFrame // -// BrowserFrame is a Window subclass that provides the window frame for the +// BrowserFrame is a WindowWin subclass that provides the window frame for the // Chrome browser window. // -class BrowserFrame : public views::Window { +class BrowserFrame : public views::WindowWin { public: explicit BrowserFrame(BrowserView* browser_view); virtual ~BrowserFrame(); diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index f8d81d9..062c2e1 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -1088,7 +1088,7 @@ bool BrowserView::GetSavedWindowBounds(gfx::Rect* bounds) const { } gfx::Rect window_rect = - frame_->GetWindowBoundsForClientBounds(*bounds); + frame_->GetNonClientView()->GetWindowBoundsForClientBounds(*bounds); window_rect.set_origin(bounds->origin()); // When we are given x/y coordinates of 0 on a created popup window, diff --git a/chrome/browser/views/frame/glass_browser_frame_view.cc b/chrome/browser/views/frame/glass_browser_frame_view.cc index 40bebe6..c822aa1 100644 --- a/chrome/browser/views/frame/glass_browser_frame_view.cc +++ b/chrome/browser/views/frame/glass_browser_frame_view.cc @@ -115,7 +115,7 @@ GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, throbber_running_(false), throbber_frame_(0) { InitClass(); - if (frame_->window_delegate()->ShouldShowWindowIcon()) + if (frame_->GetDelegate()->ShouldShowWindowIcon()) InitThrobberIcons(); } @@ -202,7 +202,7 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point)) return HTNOWHERE; - int frame_component = frame_->client_view()->NonClientHitTest(point); + int frame_component = frame_->GetClientView()->NonClientHitTest(point); if (frame_component != HTNOWHERE) return frame_component; @@ -210,7 +210,7 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, border_thickness, NonClientBorderThickness(), border_thickness, kResizeAreaCornerSize - border_thickness, - frame_->window_delegate()->CanResize()); + frame_->GetDelegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -272,7 +272,7 @@ void GlassBrowserFrameView::PaintDistributorLogo(ChromeCanvas* canvas) { void GlassBrowserFrameView::PaintToolbarBackground(ChromeCanvas* canvas) { gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds()); gfx::Point toolbar_origin(toolbar_bounds.origin()); - View::ConvertPointToView(frame_->client_view(), this, &toolbar_origin); + View::ConvertPointToView(frame_->GetClientView(), this, &toolbar_origin); toolbar_bounds.set_origin(toolbar_origin); SkBitmap* toolbar_left = @@ -306,7 +306,7 @@ void GlassBrowserFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { // The client edges start below the toolbar upper corner images regardless // of how tall the toolbar itself is. int client_area_top = - frame_->client_view()->y() + browser_view_->GetToolbarBounds().y() + + frame_->GetClientView()->y() + browser_view_->GetToolbarBounds().y() + resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT)->height(); gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc index 8452a37..01b8632 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc @@ -474,7 +474,7 @@ int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { if (!bounds().Contains(point)) return HTNOWHERE; - int frame_component = frame_->client_view()->NonClientHitTest(point); + int frame_component = frame_->GetClientView()->NonClientHitTest(point); if (frame_component != HTNOWHERE) return frame_component; @@ -496,7 +496,7 @@ int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, TopResizeHeight(), NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, - frame_->window_delegate()->CanResize()); + frame_->GetDelegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -621,13 +621,13 @@ void OpaqueBrowserFrameView::SetAccessibleName(const std::wstring& name) { void OpaqueBrowserFrameView::ButtonPressed(views::BaseButton* sender) { if (sender == minimize_button_) - frame_->ExecuteSystemMenuCommand(SC_MINIMIZE); + frame_->Minimize(); else if (sender == maximize_button_) - frame_->ExecuteSystemMenuCommand(SC_MAXIMIZE); + frame_->Maximize(); else if (sender == restore_button_) - frame_->ExecuteSystemMenuCommand(SC_RESTORE); + frame_->Restore(); else if (sender == close_button_) - frame_->ExecuteSystemMenuCommand(SC_CLOSE); + frame_->Close(); } /////////////////////////////////////////////////////////////////////////////// @@ -642,7 +642,7 @@ bool OpaqueBrowserFrameView::ShouldTabIconViewAnimate() const { } SkBitmap OpaqueBrowserFrameView::GetFavIconForTabIconView() { - return frame_->window_delegate()->GetWindowIcon(); + return frame_->GetDelegate()->GetWindowIcon(); } /////////////////////////////////////////////////////////////////////////////// @@ -663,7 +663,7 @@ int OpaqueBrowserFrameView::NonClientBorderThickness() const { } int OpaqueBrowserFrameView::NonClientTopBorderHeight() const { - if (frame_->window_delegate()->ShouldShowWindowTitle()) { + if (frame_->GetDelegate()->ShouldShowWindowTitle()) { int title_top_spacing, title_thickness; return TitleCoordinates(&title_top_spacing, &title_thickness); } @@ -772,7 +772,7 @@ void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(ChromeCanvas* canvas) { resources()->GetPartBitmap(FRAME_NO_TOOLBAR_TOP_CENTER); int edge_height = top_center->height() - kClientEdgeThickness; canvas->TileImageInt(*top_center, 0, - frame_->client_view()->y() - edge_height, width(), edge_height); + frame_->GetClientView()->y() - edge_height, width(), edge_height); } } @@ -787,7 +787,7 @@ void OpaqueBrowserFrameView::PaintDistributorLogo(ChromeCanvas* canvas) { void OpaqueBrowserFrameView::PaintTitleBar(ChromeCanvas* canvas) { // The window icon is painted by the TabIconView. - views::WindowDelegate* d = frame_->window_delegate(); + views::WindowDelegate* d = frame_->GetDelegate(); if (d->ShouldShowWindowTitle()) { canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), @@ -807,7 +807,7 @@ void OpaqueBrowserFrameView::PaintToolbarBackground(ChromeCanvas* canvas) { gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds()); gfx::Point toolbar_origin(toolbar_bounds.origin()); - View::ConvertPointToView(frame_->client_view(), this, &toolbar_origin); + View::ConvertPointToView(frame_->GetClientView(), this, &toolbar_origin); toolbar_bounds.set_origin(toolbar_origin); SkBitmap* toolbar_left = @@ -848,7 +848,7 @@ void OpaqueBrowserFrameView::PaintOTRAvatar(ChromeCanvas* canvas) { } void OpaqueBrowserFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { - int client_area_top = frame_->client_view()->y(); + int client_area_top = frame_->GetClientView()->y(); gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); if (browser_view_->IsToolbarVisible()) { @@ -991,7 +991,7 @@ void OpaqueBrowserFrameView::LayoutTitleBar() { if (!frame_->IsMaximized()) icon_y -= kIconRestoredAdjust; - views::WindowDelegate* d = frame_->window_delegate(); + views::WindowDelegate* d = frame_->GetDelegate(); if (!d->ShouldShowWindowIcon()) icon_size = 0; if (window_icon_) diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.h b/chrome/browser/views/frame/opaque_browser_frame_view.h index d62bf71..ee805f8 100644 --- a/chrome/browser/views/frame/opaque_browser_frame_view.h +++ b/chrome/browser/views/frame/opaque_browser_frame_view.h @@ -112,7 +112,7 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, // Returns the set of resources to use to paint this view. views::WindowResources* resources() const { - return frame_->is_active() || paint_as_active() ? + return frame_->IsActive() || paint_as_active() ? current_active_resources_ : current_inactive_resources_; } diff --git a/chrome/browser/views/hung_renderer_view.cc b/chrome/browser/views/hung_renderer_view.cc index 4dc72f6..ef78677 100644 --- a/chrome/browser/views/hung_renderer_view.cc +++ b/chrome/browser/views/hung_renderer_view.cc @@ -225,7 +225,7 @@ void HungRendererWarningView::ShowForWebContents(WebContents* contents) { HWND frame_hwnd = GetAncestor(contents->GetNativeView(), GA_ROOT); HWND foreground_window = GetForegroundWindow(); if (foreground_window != frame_hwnd && - foreground_window != window()->GetNativeView()) { + foreground_window != window()->GetNativeWindow()) { return; } @@ -403,8 +403,7 @@ gfx::Rect HungRendererWarningView::GetDisplayBounds( CRect contents_bounds; GetWindowRect(contents_hwnd, &contents_bounds); - gfx::Rect window_bounds; - window()->GetBounds(&window_bounds, true); + gfx::Rect window_bounds = window()->GetBounds(); int window_x = contents_bounds.left + (contents_bounds.Width() - window_bounds.width()) / 2; diff --git a/chrome/browser/views/input_window.cc b/chrome/browser/views/input_window.cc index 6add8e8..a2bc55b 100644 --- a/chrome/browser/views/input_window.cc +++ b/chrome/browser/views/input_window.cc @@ -4,6 +4,8 @@ #include "chrome/browser/views/input_window.h" +#include "base/message_loop.h" +#include "base/task.h" #include "chrome/browser/views/standard_layout.h" #include "chrome/common/l10n_util.h" #include "chrome/views/grid_layout.h" @@ -165,6 +167,6 @@ views::Window* CreateInputWindow(HWND parent_hwnd, views::Window* window = views::Window::CreateChromeWindow(parent_hwnd, gfx::Rect(), new ContentView(delegate)); - window->client_view()->AsDialogClientView()->UpdateDialogButtons(); + window->GetClientView()->AsDialogClientView()->UpdateDialogButtons(); return window; } diff --git a/chrome/browser/views/keyword_editor_view.cc b/chrome/browser/views/keyword_editor_view.cc index 86c93eb7..a19a3ce 100644 --- a/chrome/browser/views/keyword_editor_view.cc +++ b/chrome/browser/views/keyword_editor_view.cc @@ -25,6 +25,7 @@ #include "chrome/views/dialog_delegate.h" #include "chrome/views/grid_layout.h" #include "chrome/views/text_field.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc index cc44291..d3e46b2 100644 --- a/chrome/browser/views/options/advanced_contents_view.cc +++ b/chrome/browser/views/options/advanced_contents_view.cc @@ -38,6 +38,7 @@ #include "chrome/views/combo_box.h" #include "chrome/views/grid_layout.h" #include "chrome/views/scroll_view.h" +#include "chrome/views/widget.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h index 6d829bb..503bbfa 100644 --- a/chrome/browser/views/options/cookies_view.h +++ b/chrome/browser/views/options/cookies_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H__ #define CHROME_BROWSER_VIEWS_OPTIONS_COOKIES_VIEW_H__ +#include "base/task.h" #include "chrome/views/dialog_delegate.h" #include "chrome/views/native_button.h" #include "chrome/views/table_view.h" diff --git a/chrome/browser/views/page_info_window.cc b/chrome/browser/views/page_info_window.cc index ad7f1cc..99a44c3 100644 --- a/chrome/browser/views/page_info_window.cc +++ b/chrome/browser/views/page_info_window.cc @@ -670,7 +670,7 @@ void PageInfoWindow::ShowCertDialog(int cert_id) { view_info.dwSize = sizeof(view_info); // We set our parent to the tab window. This makes the cert dialog created // in CryptUIDlgViewCertificate modal to the browser. - view_info.hwndParent = window()->owning_window(); + view_info.hwndParent = window()->GetNativeWindow(); view_info.dwFlags = CRYPTUI_DISABLE_EDITPROPERTIES | CRYPTUI_DISABLE_ADDTOSTORE; view_info.pCertContext = cert->os_cert_handle(); diff --git a/chrome/browser/views/shelf_item_dialog.cc b/chrome/browser/views/shelf_item_dialog.cc index 162076b..eed4742 100644 --- a/chrome/browser/views/shelf_item_dialog.cc +++ b/chrome/browser/views/shelf_item_dialog.cc @@ -21,6 +21,7 @@ #include "chrome/views/grid_layout.h" #include "chrome/views/label.h" #include "chrome/views/text_field.h" +#include "chrome/views/widget.h" #include "grit/generated_resources.h" #include "grit/locale_settings.h" #include "grit/theme_resources.h" diff --git a/chrome/browser/views/tabs/tab_renderer.cc b/chrome/browser/views/tabs/tab_renderer.cc index f1c0e07..654acea 100644 --- a/chrome/browser/views/tabs/tab_renderer.cc +++ b/chrome/browser/views/tabs/tab_renderer.cc @@ -15,6 +15,8 @@ #include "chrome/common/l10n_util.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/win_util.h" +#include "chrome/views/non_client_view.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -499,7 +501,7 @@ void TabRenderer::OnMouseExited(const views::MouseEvent& e) { void TabRenderer::ThemeChanged() { if (GetWidget() && GetWidget()->AsWindow()) - LoadTabImages(GetWidget()->AsWindow()->UseNativeFrame()); + LoadTabImages(GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame()); View::ThemeChanged(); } @@ -534,7 +536,7 @@ void TabRenderer::PaintTabBackground(ChromeCanvas* canvas) { animation = pulse_animation_.get(); if (animation->GetCurrentValue() > 0) { PaintHoverTabBackground(canvas, animation->GetCurrentValue() * - (GetWidget()->AsWindow()->UseNativeFrame() ? + (GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame() ? kHoverOpacityVista : kHoverOpacity)); } else { PaintInactiveTabBackground(canvas); diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index 7b26c78..d2d4beb 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -25,6 +25,7 @@ #include "chrome/common/win_util.h" #include "chrome/views/image_view.h" #include "chrome/views/painter.h" +#include "chrome/views/non_client_view.h" #include "chrome/views/window.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -598,7 +599,7 @@ void TabStrip::PaintChildren(ChromeCanvas* canvas) { } } - if (GetWidget()->AsWindow()->UseNativeFrame()) { + if (GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame()) { // Make sure unselected tabs are somewhat transparent. SkPaint paint; paint.setColor(SkColorSetARGB(200, 255, 255, 255)); diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index 6b8e048..02495fc 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -354,7 +354,7 @@ void BrowserToolbarView::Paint(ChromeCanvas* canvas) { // For glass, we need to draw a black line below the location bar to separate // it from the content area. For non-glass, the NonClientView draws the // toolbar background below the location bar for us. - if (GetWidget()->AsWindow()->UseNativeFrame()) + if (GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame()) canvas->FillRectInt(SK_ColorBLACK, 0, height() - 1, width(), 1); } @@ -498,8 +498,8 @@ gfx::Size BrowserToolbarView::GetPreferredSize() { } int vertical_spacing = PopupTopSpacing() + - (GetWidget()->AsWindow()->UseNativeFrame() ? kPopupBottomSpacingGlass - : kPopupBottomSpacingNonGlass); + (GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame() ? + kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); return gfx::Size(0, location_bar_->GetPreferredSize().height() + vertical_spacing); } @@ -810,8 +810,8 @@ void BrowserToolbarView::ButtonPressed(views::BaseButton* sender) { // static int BrowserToolbarView::PopupTopSpacing() { - return GetWidget()->AsWindow()->UseNativeFrame() ? 0 - : kPopupTopSpacingNonGlass; + return GetWidget()->AsWindow()->GetNonClientView()->UseNativeFrame() ? + 0 : kPopupTopSpacingNonGlass; } void BrowserToolbarView::Observe(NotificationType type, diff --git a/chrome/browser/views/user_data_dir_dialog.cc b/chrome/browser/views/user_data_dir_dialog.cc index bc0db29..f6f814d 100644 --- a/chrome/browser/views/user_data_dir_dialog.cc +++ b/chrome/browser/views/user_data_dir_dialog.cc @@ -6,6 +6,7 @@ #include "chrome/browser/views/user_data_dir_dialog.h" #include "chrome/common/l10n_util.h" #include "chrome/views/message_box_view.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/test/interactive_ui/view_event_test_base.cc b/chrome/test/interactive_ui/view_event_test_base.cc index b2480c9..709b25d 100644 --- a/chrome/test/interactive_ui/view_event_test_base.cc +++ b/chrome/test/interactive_ui/view_event_test_base.cc @@ -57,7 +57,7 @@ void ViewEventTestBase::SetUp() { void ViewEventTestBase::TearDown() { if (window_) { - DestroyWindow(window_->GetNativeView()); + DestroyWindow(window_->GetNativeWindow()); window_ = NULL; } OleUninitialize(); @@ -79,7 +79,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() { window_->Show(); // Make sure the window is the foreground window, otherwise none of the // mouse events are going to be targeted correctly. - SetForegroundWindow(window_->GetNativeView()); + SetForegroundWindow(window_->GetNativeWindow()); // Flush any pending events to make sure we start with a clean slate. MessageLoop::current()->RunAllPending(); diff --git a/chrome/views/client_view.cc b/chrome/views/client_view.cc index 0d4cb3e..319dd56 100644 --- a/chrome/views/client_view.cc +++ b/chrome/views/client_view.cc @@ -22,7 +22,7 @@ int ClientView::NonClientHitTest(const gfx::Point& point) { } void ClientView::WindowClosing() { - window_->window_delegate()->WindowClosing(); + window_->GetDelegate()->WindowClosing(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/views/custom_frame_view.cc b/chrome/views/custom_frame_view.cc index 316d7a4..d9db4b2 100644 --- a/chrome/views/custom_frame_view.cc +++ b/chrome/views/custom_frame_view.cc @@ -260,7 +260,7 @@ CustomFrameView::CustomFrameView(Window* frame) minimize_button_->SetListener(this, -1); AddChildView(minimize_button_); - should_show_minmax_buttons_ = frame_->window_delegate()->CanMaximize(); + should_show_minmax_buttons_ = frame_->GetDelegate()->CanMaximize(); AddChildView(system_menu_button_); } @@ -311,7 +311,7 @@ int CustomFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, - frame_->window_delegate()->CanResize()); + frame_->GetDelegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -370,10 +370,11 @@ void CustomFrameView::Layout() { } gfx::Size CustomFrameView::GetPreferredSize() { - gfx::Size pref = frame_->client_view()->GetPreferredSize(); + gfx::Size pref = frame_->GetClientView()->GetPreferredSize(); DCHECK(pref.width() > 0 && pref.height() > 0); gfx::Rect bounds(0, 0, pref.width(), pref.height()); - return frame_->GetWindowBoundsForClientBounds(bounds).size(); + return frame_->GetNonClientView()->GetWindowBoundsForClientBounds( + bounds).size(); } /////////////////////////////////////////////////////////////////////////////// @@ -381,13 +382,13 @@ gfx::Size CustomFrameView::GetPreferredSize() { void CustomFrameView::ButtonPressed(BaseButton* sender) { if (sender == close_button_) - frame_->ExecuteSystemMenuCommand(SC_CLOSE); + frame_->Close(); else if (sender == minimize_button_) - frame_->ExecuteSystemMenuCommand(SC_MINIMIZE); + frame_->Minimize(); else if (sender == maximize_button_) - frame_->ExecuteSystemMenuCommand(SC_MAXIMIZE); + frame_->Maximize(); else if (sender == restore_button_) - frame_->ExecuteSystemMenuCommand(SC_RESTORE); + frame_->Restore(); } /////////////////////////////////////////////////////////////////////////////// @@ -494,11 +495,11 @@ void CustomFrameView::PaintMaximizedFrameBorder( SkBitmap* titlebar_bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); int edge_height = titlebar_bottom->height() - kClientEdgeThickness; canvas->TileImageInt(*titlebar_bottom, 0, - frame_->client_view()->y() - edge_height, width(), edge_height); + frame_->GetClientView()->y() - edge_height, width(), edge_height); } void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { - WindowDelegate* d = frame_->window_delegate(); + WindowDelegate* d = frame_->GetDelegate(); // It seems like in some conditions we can be asked to paint after the window // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The @@ -512,7 +513,7 @@ void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { } void CustomFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { - gfx::Rect client_area_bounds = frame_->client_view()->bounds(); + gfx::Rect client_area_bounds = frame_->GetClientView()->bounds(); int client_area_top = client_area_bounds.y(); SkBitmap* top_left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); @@ -655,7 +656,7 @@ void CustomFrameView::LayoutTitleBar() { if (!frame_->IsMaximized()) icon_y -= kIconRestoredAdjust; - views::WindowDelegate* d = frame_->window_delegate(); + views::WindowDelegate* d = frame_->GetDelegate(); if (!d->ShouldShowWindowIcon()) icon_size = 0; system_menu_button_->SetBounds(icon_x, icon_y, icon_size, icon_size); diff --git a/chrome/views/custom_frame_view.h b/chrome/views/custom_frame_view.h index db366a9..2a47c73 100644 --- a/chrome/views/custom_frame_view.h +++ b/chrome/views/custom_frame_view.h @@ -87,8 +87,8 @@ class CustomFrameView : public NonClientFrameView, // Returns the resource collection to be used when rendering the window. WindowResources* resources() const { - return frame_->is_active() || paint_as_active() ? active_resources_ - : inactive_resources_; + return frame_->IsActive() || paint_as_active() ? active_resources_ + : inactive_resources_; } // The bounds of the client view, in this view's coordinates. diff --git a/chrome/views/dialog_client_view.cc b/chrome/views/dialog_client_view.cc index 3908c00..74732a3 100644 --- a/chrome/views/dialog_client_view.cc +++ b/chrome/views/dialog_client_view.cc @@ -56,7 +56,7 @@ class DialogButton : public NativeButton { // Overridden to forward to the delegate. virtual bool AcceleratorPressed(const Accelerator& accelerator) { - if (!owner_->window_delegate()->AsDialogDelegate()-> + if (!owner_->GetDelegate()->AsDialogDelegate()-> AreAcceleratorsEnabled(type_)) { return false; } @@ -322,8 +322,8 @@ void DialogClientView::ButtonPressed(NativeButton* sender) { // DialogClientView, private: void DialogClientView::PaintSizeBox(ChromeCanvas* canvas) { - if (window()->window_delegate()->CanResize() || - window()->window_delegate()->CanMaximize()) { + if (window()->GetDelegate()->CanResize() || + window()->GetDelegate()->CanMaximize()) { HDC dc = canvas->beginPlatformPaint(); SIZE gripper_size = { 0, 0 }; gfx::NativeTheme::instance()->GetThemePartSize( @@ -416,7 +416,7 @@ void DialogClientView::CreateExtraView() { } DialogDelegate* DialogClientView::GetDialogDelegate() const { - DialogDelegate* dd = window()->window_delegate()->AsDialogDelegate(); + DialogDelegate* dd = window()->GetDelegate()->AsDialogDelegate(); DCHECK(dd); return dd; } diff --git a/chrome/views/dialog_delegate.cc b/chrome/views/dialog_delegate.cc index 8c29c13..d873318 100644 --- a/chrome/views/dialog_delegate.cc +++ b/chrome/views/dialog_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/views/dialog_delegate.h" +#include "base/logging.h" #include "chrome/views/window.h" namespace views { @@ -43,7 +44,7 @@ ClientView* DialogDelegate::CreateClientView(Window* window) { } DialogClientView* DialogDelegate::GetDialogClientView() const { - ClientView* client_view = window()->client_view(); + ClientView* client_view = window()->GetClientView(); DialogClientView* dialog_client_view = client_view->AsDialogClientView(); DCHECK(dialog_client_view); return dialog_client_view; diff --git a/chrome/views/native_frame_view.cc b/chrome/views/native_frame_view.cc index ee8eea2..898e105 100644 --- a/chrome/views/native_frame_view.cc +++ b/chrome/views/native_frame_view.cc @@ -4,14 +4,14 @@ #include "chrome/views/native_frame_view.h" -#include "chrome/views/window.h" +#include "chrome/views/window_win.h" namespace views { //////////////////////////////////////////////////////////////////////////////// // NativeFrameView, public: -NativeFrameView::NativeFrameView(Window* frame) +NativeFrameView::NativeFrameView(WindowWin* frame) : NonClientFrameView(), frame_(frame) { } diff --git a/chrome/views/native_frame_view.h b/chrome/views/native_frame_view.h index c46be18..c13784d 100644 --- a/chrome/views/native_frame_view.h +++ b/chrome/views/native_frame_view.h @@ -9,9 +9,11 @@ namespace views { +class WindowWin; + class NativeFrameView : public NonClientFrameView { public: - explicit NativeFrameView(Window* frame); + explicit NativeFrameView(WindowWin* frame); virtual ~NativeFrameView(); // NonClientFrameView overrides: @@ -27,7 +29,7 @@ class NativeFrameView : public NonClientFrameView { private: // Our containing frame. - Window* frame_; + WindowWin* frame_; DISALLOW_COPY_AND_ASSIGN(NativeFrameView); }; diff --git a/chrome/views/non_client_view.cc b/chrome/views/non_client_view.cc index 46bea84..984d5e9 100644 --- a/chrome/views/non_client_view.cc +++ b/chrome/views/non_client_view.cc @@ -6,6 +6,7 @@ #include "chrome/common/win_util.h" #include "chrome/views/root_view.h" +#include "chrome/views/widget.h" #include "chrome/views/window.h" namespace views { @@ -53,33 +54,6 @@ void NonClientView::WindowClosing() { client_view_->WindowClosing(); } -void NonClientView::SystemThemeChanged() { - // The window may try to paint in SetUseNativeFrame, and as a result it can - // get into a state where it is very unhappy with itself - rendering black - // behind the entire client area. This is because for some reason the - // SkPorterDuff::kClear_mode erase done in the RootView thinks the window is - // still opaque. So, to work around this we hide the window as soon as we can - // (now), saving off its placement so it can be properly restored once - // everything has settled down. - WINDOWPLACEMENT saved_window_placement; - saved_window_placement.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement(frame_->GetNativeView(), &saved_window_placement); - frame_->Hide(); - - // Important step: restore the window first, since our hiding hack doesn't - // work for maximized windows! We tell the frame not to allow itself to be - // made visible though, which removes the brief flicker. - frame_->set_force_hidden(true); - ShowWindow(frame_->GetNativeView(), SW_RESTORE); - frame_->set_force_hidden(false); - - SetUseNativeFrame(win_util::ShouldUseVistaFrame()); - - // Now that we've updated the frame, we'll want to restore our saved placement - // since the display should have settled down and we can be properly rendered. - SetWindowPlacement(frame_->GetNativeView(), &saved_window_placement); -} - void NonClientView::SetUseNativeFrame(bool use_native_frame) { use_native_frame_ = use_native_frame; SetFrameView(frame_->CreateFrameViewForWindow()); @@ -206,7 +180,7 @@ views::View* NonClientView::GetViewForPoint(const gfx::Point& point, bool NonClientFrameView::HitTest(const gfx::Point& l) const { // For the default case, we assume the non-client frame view never overlaps // the client view. - return !GetWidget()->AsWindow()->client_view()->bounds().Contains(l); + return !GetWidget()->AsWindow()->GetClientView()->bounds().Contains(l); } void NonClientFrameView::DidChangeBounds(const gfx::Rect& previous, diff --git a/chrome/views/non_client_view.h b/chrome/views/non_client_view.h index 9561052..d2ed5c1 100644 --- a/chrome/views/non_client_view.h +++ b/chrome/views/non_client_view.h @@ -137,11 +137,6 @@ class NonClientView : public View { // Called by the containing Window when it is closed. void WindowClosing(); - // Called by the window when it receives a theme changed notification. Changes - // the content of the NonClientView to match what is required for the current - // system theme. - void SystemThemeChanged(); - // Changes the frame from native to custom depending on the value of // |use_native_frame|. void SetUseNativeFrame(bool use_native_frame); diff --git a/chrome/views/table_view_unittest.cc b/chrome/views/table_view_unittest.cc index 41c985c..06f3458 100644 --- a/chrome/views/table_view_unittest.cc +++ b/chrome/views/table_view_unittest.cc @@ -4,9 +4,10 @@ #include <vector> +#include "base/message_loop.h" #include "base/string_util.h" #include "chrome/views/table_view.h" -#include "chrome/views/window.h" +#include "chrome/views/window_win.h" #include "chrome/views/window_delegate.h" #include "testing/gtest/include/gtest/gtest.h" @@ -152,7 +153,7 @@ void TableViewTest::SetUp() { } void TableViewTest::TearDown() { - window_->CloseNow(); + window_->Close(); // Temporary workaround to avoid leak of RootView::pending_paint_task_. message_loop_.RunAllPending(); OleUninitialize(); diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc index feb9182..bbb7616 100644 --- a/chrome/views/view_unittest.cc +++ b/chrome/views/view_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/message_loop.h" #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/path.h" #include "chrome/common/notification_service.h" @@ -11,6 +12,7 @@ #include "chrome/views/event.h" #include "chrome/views/root_view.h" #include "chrome/views/view.h" +#include "chrome/views/widget_win.h" #include "chrome/views/window.h" #include "testing/gtest/include/gtest/gtest.h" @@ -623,7 +625,7 @@ TEST_F(ViewTest, DialogDefaultButtonTest) { views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 100, 100), dialog_view_); views::DialogClientView* client_view = - static_cast<views::DialogClientView*>(window->client_view()); + static_cast<views::DialogClientView*>(window->GetClientView()); views::NativeButton* ok_button = client_view->ok_button(); views::NativeButton* cancel_button = client_view->cancel_button(); diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj index cbc6cd8..49e1abe 100644 --- a/chrome/views/views.vcproj +++ b/chrome/views/views.vcproj @@ -638,10 +638,6 @@ > </File> <File - RelativePath=".\window.cc" - > - </File> - <File RelativePath=".\window.h" > </File> @@ -657,6 +653,14 @@ RelativePath=".\window_resources.h" > </File> + <File + RelativePath=".\window_win.cc" + > + </File> + <File + RelativePath=".\window_win.h" + > + </File> </Files> <Globals> </Globals> diff --git a/chrome/views/window.h b/chrome/views/window.h index 9fe85dd..6ac5fb7 100644 --- a/chrome/views/window.h +++ b/chrome/views/window.h @@ -1,123 +1,34 @@ -// 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. +// Copyright (c) 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. #ifndef CHROME_VIEWS_WINDOW_H__ #define CHROME_VIEWS_WINDOW_H__ -#include "chrome/common/notification_registrar.h" -#include "chrome/views/client_view.h" -#include "chrome/views/non_client_view.h" -#include "chrome/views/widget_win.h" +#include "base/gfx/native_widget_types.h" namespace gfx { -class Point; +class Rect; class Size; -}; +} namespace views { -class Client; +class ClientView; +class NonClientFrameView; class NonClientView; class WindowDelegate; -/////////////////////////////////////////////////////////////////////////////// -// -// Window -// -// A Window is a WidgetWIn that has a caption and a border. The frame is -// rendered by the operating system. -// -/////////////////////////////////////////////////////////////////////////////// -class Window : public WidgetWin, - public NotificationObserver { +// An interface implemented by an object that provides a top level window. +class Window { public: - virtual ~Window(); + virtual ~Window() {} - // Creates the appropriate Window class for a Chrome dialog or window. This - // means a ChromeWindow or a standard Windows frame. - static Window* CreateChromeWindow(HWND parent, + // Creates an instance of an object implementing this interface. + static Window* CreateChromeWindow(gfx::NativeWindow parent, const gfx::Rect& bounds, WindowDelegate* window_delegate); - // Return the maximum size possible size the window should be have if it is - // to be positioned within the bounds of the current "work area" (screen or - // parent window). - gfx::Size CalculateMaximumSize() const; - - // Show the window. - void Show(); - void Show(int show_state); - - // Retrieve the show state of the window. This is one of the SW_SHOW* flags - // passed into Windows' ShowWindow method. For normal windows this defaults - // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this - // method to provide different values (e.g. retrieve the user's specified - // show state from the shortcut starutp info). - virtual int GetShowState() const; - - // Activate the window, assuming it already exists and is visible. - void Activate(); - - // Sizes and/or places the window to the specified bounds, size or position. - void SetBounds(const gfx::Rect& bounds); - // As above, except the window is inserted after |other_hwnd| in the window - // Z-order. If this window's HWND is not yet visible, other_hwnd's monitor - // is used as the constraining rectangle, rather than this window's hwnd's - // monitor. - void SetBounds(const gfx::Rect& bounds, HWND other_hwnd); - - // Closes the window, ultimately destroying it. - void Close(); - - // Whether or not the window is maximized or minimized. - bool IsMaximized() const; - bool IsMinimized() const; - - // Toggles the enable state for the Close button (and the Close menu item in - // the system menu). - void EnableClose(bool enable); - - // Prevents the window from being rendered as deactivated the next time it is. - // This state is reset automatically as soon as the window becomes actiated - // again. There is no ability to control the state through this API as this - // leads to sync problems. - void DisableInactiveRendering(); - - // Tell the window to update its title from the delegate. - void UpdateWindowTitle(); - - // Tell the window to update its icon from the delegate. - void UpdateWindowIcon(); - - // Executes the specified SC_command. - void ExecuteSystemMenuCommand(int command); - - // Shortcut to access the determination of whether or not we're using a - // native frame. This triggers different rendering modes in certain views and - // should be used in preference to calling win_util::ShouldUseVistaFrame. - bool UseNativeFrame() const { return non_client_view_->UseNativeFrame(); } - - // Returns the bounds of the window required to display the content area - // at the specified bounds. - gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect& client_bounds); - - // Creates an appropriate NonClientFrameView for this window. - virtual NonClientFrameView* CreateFrameViewForWindow(); - - // Updates the frame after an event caused it to be changed. - virtual void UpdateFrameAfterFrameChange(); - - // Accessors and setters for various properties. - WindowDelegate* window_delegate() const { return window_delegate_; } - HWND owning_window() const { return owning_hwnd_; } - ClientView* client_view() const { return non_client_view_->client_view(); } - bool is_active() const { return is_active_; } - void set_focus_on_creation(bool focus_on_creation) { - focus_on_creation_ = focus_on_creation; - } - void set_force_hidden(bool force_hidden) { force_hidden_ = force_hidden; } - // Returns the preferred size of the contents view of this window based on // its localized size data. The width in cols is held in a localized string // resource identified by |col_resource_id|, the height in the same fashion. @@ -128,196 +39,80 @@ class Window : public WidgetWin, static gfx::Size GetLocalizedContentsSize(int col_resource_id, int row_resource_id); - // NotificationObserver overrides: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - 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); + // Retrieves the window's bounds, including its frame. + virtual gfx::Rect GetBounds() const = 0; - // Sizes the window to the default size specified by its ClientView. - virtual void SizeWindowToDefault(); - - // Returns true if the Window is considered to be an "app window" - i.e. any - // window which when it is the last of its type closed causes the application - // to exit. - virtual bool IsAppWindow() const { return false; } - - // Shows the system menu at the specified screen point. - void RunSystemMenu(const gfx::Point& point); - - // Overridden from WidgetWin: - virtual void OnActivate(UINT action, BOOL minimized, HWND window); - virtual void OnActivateApp(BOOL active, DWORD thread_id); - virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, - int keystate); - virtual void OnCommand(UINT notification_code, int command_id, HWND window); - virtual void OnDestroy(); - virtual LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, - LPARAM l_param); - virtual void OnFinalMessage(HWND window); - virtual void OnInitMenu(HMENU menu); - virtual void OnMouseLeave(); - virtual LRESULT OnNCActivate(BOOL active); - virtual LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); - virtual LRESULT OnNCHitTest(const CPoint& point); - virtual void OnNCPaint(HRGN rgn); - virtual void OnNCLButtonDown(UINT ht_component, const CPoint& point); - virtual void OnNCRButtonDown(UINT ht_component, const CPoint& point); - virtual LRESULT OnNCUAHDrawCaption(UINT msg, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message); - virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); - virtual LRESULT OnSetText(const wchar_t* text); - virtual void OnSize(UINT size_param, const CSize& new_size); - virtual void OnSysCommand(UINT notification_code, CPoint click); - virtual void OnWindowPosChanging(WINDOWPOS* window_pos); - virtual Window* AsWindow() { return this; } - virtual const Window* AsWindow() const { return this; } - - // The View that provides the non-client area of the window (title bar, - // window controls, sizing borders etc). To use an implementation other than - // the default, this class must be subclassed and this value set to the - // desired implementation before calling |Init|. - NonClientView* non_client_view_; - - // Accessor for disable_inactive_rendering_. - bool disable_inactive_rendering() const { - return disable_inactive_rendering_; - } - - private: - // Set the window as modal (by disabling all the other windows). - void BecomeModal(); - - // Sets-up the focus manager with the view that should have focus when the - // window is shown the first time. If NULL is returned, the focus goes to the - // button if there is one, otherwise the to the Cancel button. - void SetInitialFocus(); - - // Place and size the window when it is created. |create_bounds| are the - // bounds used when the window was created. - void SetInitialBounds(const gfx::Rect& create_bounds); - - // Restore saved always on stop state and add the always on top system menu - // if needed. - void InitAlwaysOnTopState(); - - // Add an item for "Always on Top" to the System Menu. - void AddAlwaysOnTopSystemMenuItem(); - - // If necessary, enables all ancestors. - void RestoreEnabledIfNecessary(); - - // Update the window style to reflect the always on top state. - void AlwaysOnTopChanged(); - - // Calculate the appropriate window styles for this window. - DWORD CalculateWindowStyle(); - DWORD CalculateWindowExStyle(); - - // Asks the delegate if any to save the window's location and size. - void SaveWindowPosition(); - - // Lock or unlock the window from being able to redraw itself in response to - // updates to its invalid region. - class ScopedRedrawLock; - void LockUpdates(); - void UnlockUpdates(); - - // Resets the window region for the current window bounds if necessary. - // If |force| is true, the window region is reset to NULL even for native - // frame windows. - void ResetWindowRegion(bool force); - - // Converts a non-client mouse down message to a regular ChromeViews event - // and handle it. |point| is the mouse position of the message in screen - // coords. |flags| are flags that would be passed with a WM_L/M/RBUTTON* - // message and relate to things like which button was pressed. These are - // combined with flags relating to the current key state. - void ProcessNCMousePress(const CPoint& point, int flags); - - // Calls the default WM_NCACTIVATE handler with the specified activation - // value, safely wrapping the call in a ScopedRedrawLock to prevent frame - // flicker. - LRESULT CallDefaultNCActivateHandler(BOOL active); - - // Static resource initialization. - static void InitClass(); - enum ResizeCursor { - RC_NORMAL = 0, RC_VERTICAL, RC_HORIZONTAL, RC_NESW, RC_NWSE - }; - static HCURSOR resize_cursors_[6]; + // Sizes and/or places the window to the specified bounds, size or position. + virtual void SetBounds(const gfx::Rect& bounds) = 0; + + // As above, except the window is inserted after |other_window| in the window + // Z-order. If this window is not yet visible, other_window's monitor is used + // as the constraining rectangle, rather than this window's monitor. + virtual void SetBounds(const gfx::Rect& bounds, + gfx::NativeWindow other_window) = 0; - // Our window delegate (see Init method for documentation). - WindowDelegate* window_delegate_; + // Makes the window visible. + virtual void Show() = 0; - // Whether we should SetFocus() on a newly created window after - // Init(). Defaults to true. - bool focus_on_creation_; + // Activate the window, assuming it already exists and is visible. + virtual void Activate() = 0; - // We need to save the parent window that spawned us, since GetParent() - // returns NULL for dialogs. - HWND owning_hwnd_; + // Closes the window, ultimately destroying it. This isn't immediate (it + // occurs after a return to the message loop. Implementors must also make sure + // that invoking Close multiple times doesn't cause bad things to happen, + // since it can happen. + virtual void Close() = 0; - // The smallest size the window can be. - CSize minimum_size_; + // Maximizes/minimizes/restores the window. + virtual void Maximize() = 0; + virtual void Minimize() = 0; + virtual void Restore() = 0; - // Whether or not the window is modal. This comes from the delegate and is - // cached at Init time to avoid calling back to the delegate from the - // destructor. - bool is_modal_; + // Whether or not the window is currently active. + virtual bool IsActive() const = 0; - // Whether all ancestors have been enabled. This is only used if is_modal_ is - // true. - bool restored_enabled_; + // Whether or not the window is currently visible. + virtual bool IsVisible() const = 0; - // Whether the window is currently always on top. - bool is_always_on_top_; + // Whether or not the window is maximized or minimized. + virtual bool IsMaximized() const = 0; + virtual bool IsMinimized() const = 0; - // We need to own the text of the menu, the Windows API does not copy it. - std::wstring always_on_top_menu_text_; + // Toggles the enable state for the Close button (and the Close menu item in + // the system menu). + virtual void EnableClose(bool enable) = 0; - // Set to true if the window is in the process of closing . - bool window_closed_; + // Prevents the window from being rendered as deactivated the next time it is. + // This state is reset automatically as soon as the window becomes activated + // again. There is no ability to control the state through this API as this + // leads to sync problems. + virtual void DisableInactiveRendering() = 0; - // True when the window should be rendered as active, regardless of whether - // or not it actually is. - bool disable_inactive_rendering_; + // Tell the window to update its title from the delegate. + virtual void UpdateWindowTitle() = 0; - // True if this window is the active top level window. - bool is_active_; + // Tell the window to update its icon from the delegate. + virtual void UpdateWindowIcon() = 0; - // True if updates to this window are currently locked. - bool lock_updates_; + // Creates an appropriate NonClientFrameView for this window. + virtual NonClientFrameView* CreateFrameViewForWindow() = 0; - // The window styles of the window before updates were locked. - DWORD saved_window_style_; + // Updates the frame after an event caused it to be changed. + virtual void UpdateFrameAfterFrameChange() = 0; - // The saved maximized state for this window. See note in SetInitialBounds - // that explains why we save this. - bool saved_maximized_state_; + // Retrieves the Window's delegate. + virtual WindowDelegate* GetDelegate() const = 0; - // True if we should prevent attempts to make the window visible when we - // handle WM_WINDOWPOSCHANGING. Some calls like ShowWindow(SW_RESTORE) make - // the window visible in addition to restoring it, when all we want to do is - // restore it. - bool force_hidden_; + // Retrieves the Window's non-client view. + virtual NonClientView* GetNonClientView() const = 0; - // Hold onto notifications. - NotificationRegistrar notification_registrar_; + // Retrieves the Window's client view. + virtual ClientView* GetClientView() const = 0; - DISALLOW_COPY_AND_ASSIGN(Window); + // Retrieves the Window's native window handle. + virtual gfx::NativeWindow GetNativeWindow() const = 0; }; } // namespace views -#endif // CHROME_VIEWS_WINDOW_H__ +#endif // #ifndef CHROME_VIEWS_WINDOW_H__ diff --git a/chrome/views/window_delegate.h b/chrome/views/window_delegate.h index bbd5296..985ed60 100644 --- a/chrome/views/window_delegate.h +++ b/chrome/views/window_delegate.h @@ -148,7 +148,7 @@ class WindowDelegate { void ReleaseWindow(); private: - friend class Window; + friend class WindowWin; // This is a little unusual. We use a scoped_ptr here because it's // initialized to NULL automatically. We do this because we want to allow // people using this helper to not have to call a ctor on this object. diff --git a/chrome/views/window.cc b/chrome/views/window_win.cc index 4bf24ee..e2226d7 100644 --- a/chrome/views/window.cc +++ b/chrome/views/window_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/views/window.h" +#include "chrome/views/window_win.h" #include <shellapi.h> @@ -52,9 +52,9 @@ namespace views { // // I would love to hear Raymond Chen's explanation for all this. And maybe a // list of other messages that this applies to ;-) -class Window::ScopedRedrawLock { +class WindowWin::ScopedRedrawLock { public: - explicit ScopedRedrawLock(Window* window) : window_(window) { + explicit ScopedRedrawLock(WindowWin* window) : window_(window) { window_->LockUpdates(); } @@ -64,10 +64,10 @@ class Window::ScopedRedrawLock { private: // The window having its style changed. - Window* window_; + WindowWin* window_; }; -HCURSOR Window::resize_cursors_[6]; +HCURSOR WindowWin::resize_cursors_[6]; // If the hung renderer warning doesn't fit on screen, the amount of padding to // be left between the edge of the window and the edge of the nearest monitor, @@ -75,53 +75,38 @@ HCURSOR Window::resize_cursors_[6]; static const int kMonitorEdgePadding = 10; //////////////////////////////////////////////////////////////////////////////// -// Window, public: +// WindowWin, public: -Window::~Window() { +WindowWin::~WindowWin() { } // static -Window* Window::CreateChromeWindow(HWND parent, +Window* Window::CreateChromeWindow(gfx::NativeWindow parent, const gfx::Rect& bounds, WindowDelegate* window_delegate) { - Window* window = new Window(window_delegate); - window->non_client_view_->SetFrameView(window->CreateFrameViewForWindow()); + WindowWin* window = new WindowWin(window_delegate); + window->GetNonClientView()->SetFrameView(window->CreateFrameViewForWindow()); window->Init(parent, bounds); return window; } -gfx::Size Window::CalculateMaximumSize() const { - // If this is a top level window, the maximum size is the size of the working - // rect of the display the window is on, less padding. If this is a child - // (constrained) window, the maximum size of this Window are the bounds of the - // parent window, less padding. - DCHECK(GetNativeView()) << "Cannot calculate maximum size before Init() is called"; - gfx::Rect working_rect; - HWND parent_hwnd = ::GetParent(GetNativeView()); - if (parent_hwnd) { - RECT parent_rect; - ::GetClientRect(parent_hwnd, &parent_rect); - working_rect = parent_rect; - } else { - HMONITOR current_monitor = - ::MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST); - MONITORINFO mi; - mi.cbSize = sizeof(mi); - ::GetMonitorInfo(current_monitor, &mi); - working_rect = mi.rcWork; - } - working_rect.Inset(kMonitorEdgePadding, kMonitorEdgePadding); - return working_rect.size(); +gfx::Rect WindowWin::GetBounds() const { + gfx::Rect bounds; + WidgetWin::GetBounds(&bounds, true); + return bounds; } -void Window::Show() { - int show_state = GetShowState(); - if (saved_maximized_state_) - show_state = SW_SHOWMAXIMIZED; - Show(show_state); +void WindowWin::SetBounds(const gfx::Rect& bounds) { + SetBounds(bounds, NULL); } -void Window::Show(int show_state) { +void WindowWin::SetBounds(const gfx::Rect& bounds, + gfx::NativeWindow other_window) { + win_util::SetChildBounds(GetNativeView(), GetParent(), other_window, bounds, + kMonitorEdgePadding, 0); +} + +void WindowWin::Show(int show_state) { ShowWindow(show_state); // When launched from certain programs like bash and Windows Live Messenger, // show_state is set to SW_HIDE, so we need to correct that condition. We @@ -144,27 +129,60 @@ void Window::Show(int show_state) { SetInitialFocus(); } -int Window::GetShowState() const { +int WindowWin::GetShowState() const { return SW_SHOWNORMAL; } -void Window::Activate() { - if (IsMinimized()) - ::ShowWindow(GetNativeView(), SW_RESTORE); - ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); - SetForegroundWindow(GetNativeView()); +void WindowWin::ExecuteSystemMenuCommand(int command) { + if (command) + SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); } -void Window::SetBounds(const gfx::Rect& bounds) { - SetBounds(bounds, NULL); +// static +int Window::GetLocalizedContentsWidth(int col_resource_id) { + double chars = _wtof(l10n_util::GetString(col_resource_id).c_str()); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ChromeFont font = rb.GetFont(ResourceBundle::BaseFont); + int width = font.GetExpectedTextWidth(static_cast<int>(chars)); + DCHECK(width > 0); + return width; } -void Window::SetBounds(const gfx::Rect& bounds, HWND other_hwnd) { - win_util::SetChildBounds(GetNativeView(), GetParent(), other_hwnd, bounds, - kMonitorEdgePadding, 0); +// static +int Window::GetLocalizedContentsHeight(int row_resource_id) { + double lines = _wtof(l10n_util::GetString(row_resource_id).c_str()); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + ChromeFont font = rb.GetFont(ResourceBundle::BaseFont); + int height = static_cast<int>(font.height() * lines); + DCHECK(height > 0); + return height; +} + +// static +gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, + int row_resource_id) { + return gfx::Size(GetLocalizedContentsWidth(col_resource_id), + GetLocalizedContentsHeight(row_resource_id)); } -void Window::Close() { +//////////////////////////////////////////////////////////////////////////////// +// WindowWin, Window implementation: + +void WindowWin::Show() { + int show_state = GetShowState(); + if (saved_maximized_state_) + show_state = SW_SHOWMAXIMIZED; + Show(show_state); +} + +void WindowWin::Activate() { + if (IsMinimized()) + ::ShowWindow(GetNativeView(), SW_RESTORE); + ::SetWindowPos(GetNativeView(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + SetForegroundWindow(GetNativeView()); +} + +void WindowWin::Close() { if (window_closed_) { // It appears we can hit this code path if you close a modal dialog then // close the last browser before the destructor is hit, which triggers @@ -189,15 +207,35 @@ void Window::Close() { } } -bool Window::IsMaximized() const { +void WindowWin::Maximize() { + ExecuteSystemMenuCommand(SC_MAXIMIZE); +} + +void WindowWin::Minimize() { + ExecuteSystemMenuCommand(SC_MINIMIZE); +} + +void WindowWin::Restore() { + ExecuteSystemMenuCommand(SC_RESTORE); +} + +bool WindowWin::IsActive() const { + return is_active_; +} + +bool WindowWin::IsVisible() const { + return !!::IsWindowVisible(GetNativeView()); +} + +bool WindowWin::IsMaximized() const { return !!::IsZoomed(GetNativeView()); } -bool Window::IsMinimized() const { +bool WindowWin::IsMinimized() const { return !!::IsIconic(GetNativeView()); } -void Window::EnableClose(bool enable) { +void WindowWin::EnableClose(bool enable) { // If the native frame is rendering its own close button, ask it to disable. non_client_view_->EnableClose(enable); @@ -213,12 +251,12 @@ void Window::EnableClose(bool enable) { SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER); } -void Window::DisableInactiveRendering() { +void WindowWin::DisableInactiveRendering() { disable_inactive_rendering_ = true; non_client_view_->DisableInactiveRendering(disable_inactive_rendering_); } -void Window::UpdateWindowTitle() { +void WindowWin::UpdateWindowTitle() { // If the non-client view is rendering its own title, it'll need to relayout // now. non_client_view_->Layout(); @@ -232,7 +270,7 @@ void Window::UpdateWindowTitle() { SetWindowText(GetNativeView(), window_title.c_str()); } -void Window::UpdateWindowIcon() { +void WindowWin::UpdateWindowIcon() { // If the non-client view is rendering its own icon, we need to tell it to // repaint. non_client_view_->SchedulePaint(); @@ -257,49 +295,39 @@ void Window::UpdateWindowIcon() { } } -void Window::ExecuteSystemMenuCommand(int command) { - if (command) - SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0); +NonClientFrameView* WindowWin::CreateFrameViewForWindow() { + if (non_client_view_->UseNativeFrame()) + return new NativeFrameView(this); + return new CustomFrameView(this); } -gfx::Rect Window::GetWindowBoundsForClientBounds( - const gfx::Rect& client_bounds) { - return non_client_view_->GetWindowBoundsForClientBounds(client_bounds); +void WindowWin::UpdateFrameAfterFrameChange() { + // We've either gained or lost a custom window region, so reset it now. + ResetWindowRegion(true); } -// static -int Window::GetLocalizedContentsWidth(int col_resource_id) { - double chars = _wtof(l10n_util::GetString(col_resource_id).c_str()); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - ChromeFont font = rb.GetFont(ResourceBundle::BaseFont); - int width = font.GetExpectedTextWidth(static_cast<int>(chars)); - DCHECK(width > 0); - return width; +WindowDelegate* WindowWin::GetDelegate() const { + return window_delegate_; } -// static -int Window::GetLocalizedContentsHeight(int row_resource_id) { - double lines = _wtof(l10n_util::GetString(row_resource_id).c_str()); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - ChromeFont font = rb.GetFont(ResourceBundle::BaseFont); - int height = static_cast<int>(font.height() * lines); - DCHECK(height > 0); - return height; +NonClientView* WindowWin::GetNonClientView() const { + return non_client_view_; } -// static -gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, - int row_resource_id) { - return gfx::Size(GetLocalizedContentsWidth(col_resource_id), - GetLocalizedContentsHeight(row_resource_id)); +ClientView* WindowWin::GetClientView() const { + return non_client_view_->client_view(); +} + +gfx::NativeWindow WindowWin::GetNativeWindow() const { + return GetNativeView(); } //////////////////////////////////////////////////////////////////////////////// -// Window, NotificationObserver implementation: +// WindowWin, NotificationObserver implementation: -void Window::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { +void WindowWin::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { // This window is closed when the last app window is closed. DCHECK(type == NotificationType::ALL_APPWINDOWS_CLOSED); // Only registered as an observer when we're not an app window. @@ -308,9 +336,9 @@ void Window::Observe(NotificationType type, } /////////////////////////////////////////////////////////////////////////////// -// Window, protected: +// WindowWin, protected: -Window::Window(WindowDelegate* window_delegate) +WindowWin::WindowWin(WindowDelegate* window_delegate) : WidgetWin(), focus_on_creation_(true), window_delegate_(window_delegate), @@ -336,7 +364,7 @@ Window::Window(WindowDelegate* window_delegate) set_window_ex_style(0); } -void Window::Init(HWND parent, const gfx::Rect& bounds) { +void WindowWin::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; @@ -375,24 +403,13 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) { ResetWindowRegion(false); } -NonClientFrameView* Window::CreateFrameViewForWindow() { - if (non_client_view_->UseNativeFrame()) - return new NativeFrameView(this); - return new CustomFrameView(this); -} - -void Window::UpdateFrameAfterFrameChange() { - // We've either gained or lost a custom window region, so reset it now. - ResetWindowRegion(true); -} - -void Window::SizeWindowToDefault() { +void WindowWin::SizeWindowToDefault() { win_util::CenterAndSizeWindow(owning_window(), GetNativeView(), non_client_view_->GetPreferredSize().ToSIZE(), false); } -void Window::RunSystemMenu(const gfx::Point& point) { +void WindowWin::RunSystemMenu(const gfx::Point& point) { // We need to reset and clean up any currently created system menu objects. // We need to call this otherwise there's a small chance that we aren't going // to get a system menu. We also can't take the return value of this @@ -406,14 +423,14 @@ void Window::RunSystemMenu(const gfx::Point& point) { } /////////////////////////////////////////////////////////////////////////////// -// Window, WidgetWin overrides: +// WindowWin, WidgetWin overrides: -void Window::OnActivate(UINT action, BOOL minimized, HWND window) { +void WindowWin::OnActivate(UINT action, BOOL minimized, HWND window) { if (action == WA_INACTIVE) SaveWindowPosition(); } -void Window::OnActivateApp(BOOL active, DWORD thread_id) { +void WindowWin::OnActivateApp(BOOL active, DWORD thread_id) { if (!active && thread_id != GetCurrentThreadId()) { // Another application was activated, we should reset any state that // disables inactive rendering now. @@ -425,8 +442,8 @@ void Window::OnActivateApp(BOOL active, DWORD thread_id) { } } -LRESULT Window::OnAppCommand(HWND window, short app_command, WORD device, - int keystate) { +LRESULT WindowWin::OnAppCommand(HWND window, short app_command, WORD device, + int keystate) { // We treat APPCOMMAND ids as an extension of our command namespace, and just // let the delegate figure out what to do... if (!window_delegate_->ExecuteWindowsCommand(app_command)) @@ -434,7 +451,7 @@ LRESULT Window::OnAppCommand(HWND window, short app_command, WORD device, return 0; } -void Window::OnCommand(UINT notification_code, int command_id, HWND window) { +void WindowWin::OnCommand(UINT notification_code, int command_id, HWND window) { // If the notification code is > 1 it means it is control specific and we // should ignore it. if (notification_code > 1 || @@ -443,7 +460,7 @@ void Window::OnCommand(UINT notification_code, int command_id, HWND window) { } } -void Window::OnDestroy() { +void WindowWin::OnDestroy() { non_client_view_->WindowClosing(); RestoreEnabledIfNecessary(); WidgetWin::OnDestroy(); @@ -456,12 +473,35 @@ static BOOL CALLBACK SendDwmCompositionChanged(HWND window, LPARAM param) { } } // namespace -LRESULT Window::OnDwmCompositionChanged(UINT msg, WPARAM w_param, - LPARAM l_param) { +LRESULT WindowWin::OnDwmCompositionChanged(UINT msg, WPARAM w_param, + LPARAM l_param) { + // The window may try to paint in SetUseNativeFrame, and as a result it can + // get into a state where it is very unhappy with itself - rendering black + // behind the entire client area. This is because for some reason the + // SkPorterDuff::kClear_mode erase done in the RootView thinks the window is + // still opaque. So, to work around this we hide the window as soon as we can + // (now), saving off its placement so it can be properly restored once + // everything has settled down. + WINDOWPLACEMENT saved_window_placement; + saved_window_placement.length = sizeof(WINDOWPLACEMENT); + GetWindowPlacement(GetNativeView(), &saved_window_placement); + Hide(); + + // Important step: restore the window first, since our hiding hack doesn't + // work for maximized windows! We tell the frame not to allow itself to be + // made visible though, which removes the brief flicker. + force_hidden_ = true; + ::ShowWindow(GetNativeView(), SW_RESTORE); + force_hidden_ = false; + // We respond to this in response to WM_DWMCOMPOSITIONCHANGED since that is // the only thing we care about - we don't actually respond to WM_THEMECHANGED // messages. - non_client_view_->SystemThemeChanged(); + non_client_view_->SetUseNativeFrame(win_util::ShouldUseVistaFrame()); + + // Now that we've updated the frame, we'll want to restore our saved placement + // since the display should have settled down and we can be properly rendered. + SetWindowPlacement(GetNativeView(), &saved_window_placement); // WM_DWMCOMPOSITIONCHANGED is only sent to top level windows, however we want // to notify our children too, since we can have MDI child windows who need to @@ -470,7 +510,7 @@ LRESULT Window::OnDwmCompositionChanged(UINT msg, WPARAM w_param, return 0; } -void Window::OnFinalMessage(HWND window) { +void WindowWin::OnFinalMessage(HWND window) { // Delete and NULL the delegate here once we're guaranteed to get no more // messages. window_delegate_->DeleteDelegate(); @@ -485,7 +525,7 @@ static void EnableMenuItem(HMENU menu, UINT command, bool enabled) { } } // namespace -void Window::OnInitMenu(HMENU menu) { +void WindowWin::OnInitMenu(HMENU menu) { // We only need to manually enable the system menu if we're not using a native // frame. if (non_client_view_->UseNativeFrame()) @@ -498,14 +538,14 @@ void Window::OnInitMenu(HMENU menu) { ScopedRedrawLock lock(this); EnableMenuItem(menu, SC_RESTORE, !is_restored); EnableMenuItem(menu, SC_MOVE, is_restored); - EnableMenuItem(menu, SC_SIZE, window_delegate()->CanResize() && is_restored); + EnableMenuItem(menu, SC_SIZE, window_delegate_->CanResize() && is_restored); EnableMenuItem(menu, SC_MAXIMIZE, - window_delegate()->CanMaximize() && !is_maximized); + window_delegate_->CanMaximize() && !is_maximized); EnableMenuItem(menu, SC_MINIMIZE, - window_delegate()->CanMaximize() && !is_minimized); + window_delegate_->CanMaximize() && !is_minimized); } -void Window::OnMouseLeave() { +void WindowWin::OnMouseLeave() { // We only need to manually track WM_MOUSELEAVE messages between the client // and non-client area when we're not using the native frame. if (non_client_view_->UseNativeFrame()) { @@ -532,7 +572,7 @@ void Window::OnMouseLeave() { ProcessMouseExited(); } -LRESULT Window::OnNCActivate(BOOL active) { +LRESULT WindowWin::OnNCActivate(BOOL active) { is_active_ = !!active; // If we're not using the native frame, we need to force a synchronous repaint @@ -553,7 +593,7 @@ LRESULT Window::OnNCActivate(BOOL active) { // tell the non-client view. This must be done independently of the check for // disable_inactive_rendering_ since that check is valid even if the frame // is not active, but this can only be done if we've become active. - if (is_active_) + if (IsActive()) non_client_view_->DisableInactiveRendering(false); // Reset the disable inactive rendering state since activation has changed. @@ -564,7 +604,7 @@ LRESULT Window::OnNCActivate(BOOL active) { return CallDefaultNCActivateHandler(active); } -LRESULT Window::OnNCCalcSize(BOOL mode, LPARAM l_param) { +LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { // We only need to adjust the client size/paint handling when we're not using // the native frame. if (non_client_view_->UseNativeFrame()) @@ -607,7 +647,7 @@ LRESULT Window::OnNCCalcSize(BOOL mode, LPARAM l_param) { return mode ? WVR_REDRAW : 0; } -LRESULT Window::OnNCHitTest(const CPoint& point) { +LRESULT WindowWin::OnNCHitTest(const CPoint& point) { // First, give the NonClientView a chance to test the point to see if it // provides any of the non-client area. CPoint temp = point; @@ -650,7 +690,7 @@ static BOOL CALLBACK ClipDCToChild(HWND window, LPARAM param) { } } // namespace -void Window::OnNCPaint(HRGN rgn) { +void WindowWin::OnNCPaint(HRGN rgn) { // We only do non-client painting if we're not using the native frame. if (non_client_view_->UseNativeFrame()) { WidgetWin::OnNCPaint(rgn); @@ -726,7 +766,7 @@ void Window::OnNCPaint(HRGN rgn) { ReleaseDC(GetNativeView(), dc); } -void Window::OnNCLButtonDown(UINT ht_component, const CPoint& point) { +void WindowWin::OnNCLButtonDown(UINT ht_component, const CPoint& point) { // When we're using a native frame, window controls work without us // interfering. if (!non_client_view_->UseNativeFrame()) { @@ -765,7 +805,7 @@ void Window::OnNCLButtonDown(UINT ht_component, const CPoint& point) { /* TODO(beng): Fix the standard non-client over-painting bug. This code doesn't work but identifies the problem. if (!IsMsgHandled()) { - // Window::OnNCLButtonDown set the message as unhandled. This normally + // WindowWin::OnNCLButtonDown set the message as unhandled. This normally // means WidgetWin::ProcessWindowMessage will pass it to // DefWindowProc. Sadly, DefWindowProc for WM_NCLBUTTONDOWN does weird // non-client painting, so we need to call it directly here inside a @@ -778,30 +818,30 @@ void Window::OnNCLButtonDown(UINT ht_component, const CPoint& point) { */ } -void Window::OnNCRButtonDown(UINT ht_component, const CPoint& point) { +void WindowWin::OnNCRButtonDown(UINT ht_component, const CPoint& point) { if (ht_component == HTCAPTION || ht_component == HTSYSMENU) RunSystemMenu(gfx::Point(point)); else WidgetWin::OnNCRButtonDown(ht_component, point); } -LRESULT Window::OnNCUAHDrawCaption(UINT msg, WPARAM w_param, - LPARAM l_param) { +LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param, + LPARAM l_param) { // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for // an explanation about why we need to handle this message. SetMsgHandled(!non_client_view_->UseNativeFrame()); return 0; } -LRESULT Window::OnNCUAHDrawFrame(UINT msg, WPARAM w_param, - LPARAM l_param) { +LRESULT WindowWin::OnNCUAHDrawFrame(UINT msg, WPARAM w_param, + LPARAM l_param) { // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for // an explanation about why we need to handle this message. SetMsgHandled(!non_client_view_->UseNativeFrame()); return 0; } -LRESULT Window::OnSetCursor(HWND window, UINT hittest_code, UINT message) { +LRESULT WindowWin::OnSetCursor(HWND window, UINT hittest_code, UINT message) { // If the window is disabled, it's because we're showing a modal dialog box. // We need to let DefWindowProc handle the message. That's because // DefWindowProc for WM_SETCURSOR with message = some kind of mouse button @@ -842,21 +882,21 @@ LRESULT Window::OnSetCursor(HWND window, UINT hittest_code, UINT message) { return 0; } -LRESULT Window::OnSetIcon(UINT size_type, HICON new_icon) { +LRESULT WindowWin::OnSetIcon(UINT size_type, HICON new_icon) { // This shouldn't hurt even if we're using the native frame. ScopedRedrawLock lock(this); return DefWindowProc(GetNativeView(), WM_SETICON, size_type, reinterpret_cast<LPARAM>(new_icon)); } -LRESULT Window::OnSetText(const wchar_t* text) { +LRESULT WindowWin::OnSetText(const wchar_t* text) { // This shouldn't hurt even if we're using the native frame. ScopedRedrawLock lock(this); return DefWindowProc(GetNativeView(), WM_SETTEXT, NULL, reinterpret_cast<LPARAM>(text)); } -void Window::OnSize(UINT size_param, const CSize& new_size) { +void WindowWin::OnSize(UINT size_param, const CSize& new_size) { // Don't no-op if the new_size matches current size. If our normal bounds // and maximized bounds are the same, then we need to layout (because we // layout differently when maximized). @@ -869,7 +909,7 @@ void Window::OnSize(UINT size_param, const CSize& new_size) { ResetWindowRegion(false); } -void Window::OnSysCommand(UINT notification_code, CPoint click) { +void WindowWin::OnSysCommand(UINT notification_code, CPoint click) { if (!non_client_view_->UseNativeFrame()) { // Windows uses the 4 lower order bits of |notification_code| for type- // specific information so we must exclude this when comparing. @@ -921,7 +961,7 @@ void Window::OnSysCommand(UINT notification_code, CPoint click) { } } -void Window::OnWindowPosChanging(WINDOWPOS* window_pos) { +void WindowWin::OnWindowPosChanging(WINDOWPOS* window_pos) { if (force_hidden_) { // Prevent the window from being made visible if we've been asked to do so. // See comment in header as to why we might want this. @@ -931,9 +971,9 @@ void Window::OnWindowPosChanging(WINDOWPOS* window_pos) { } //////////////////////////////////////////////////////////////////////////////// -// Window, private: +// WindowWin, private: -void Window::BecomeModal() { +void WindowWin::BecomeModal() { // We implement modality by crawling up the hierarchy of windows starting // at the owner, disabling all of them so that they don't receive input // messages. @@ -945,7 +985,7 @@ void Window::BecomeModal() { } } -void Window::SetInitialFocus() { +void WindowWin::SetInitialFocus() { if (!focus_on_creation_) return; @@ -959,7 +999,7 @@ void Window::SetInitialFocus() { } } -void Window::SetInitialBounds(const gfx::Rect& create_bounds) { +void WindowWin::SetInitialBounds(const gfx::Rect& create_bounds) { // First we obtain the window's saved show-style and store it. We need to do // this here, rather than in Show() because by the time Show() is called, // the window's size will have been reset (below) and the saved maximized @@ -1004,7 +1044,7 @@ void Window::SetInitialBounds(const gfx::Rect& create_bounds) { } } -void Window::InitAlwaysOnTopState() { +void WindowWin::InitAlwaysOnTopState() { is_always_on_top_ = false; if (window_delegate_->GetSavedAlwaysOnTopState(&is_always_on_top_) && is_always_on_top_ != window_delegate_->IsAlwaysOnTop()) { @@ -1015,7 +1055,7 @@ void Window::InitAlwaysOnTopState() { AddAlwaysOnTopSystemMenuItem(); } -void Window::AddAlwaysOnTopSystemMenuItem() { +void WindowWin::AddAlwaysOnTopSystemMenuItem() { // The Win32 API requires that we own the text. always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP); @@ -1046,7 +1086,7 @@ void Window::AddAlwaysOnTopSystemMenuItem() { ::InsertMenuItem(system_menu, index, TRUE, &menu_info); } -void Window::RestoreEnabledIfNecessary() { +void WindowWin::RestoreEnabledIfNecessary() { if (is_modal_ && !restored_enabled_) { restored_enabled_ = true; // If we were run modally, we need to undo the disabled-ness we inflicted on @@ -1059,14 +1099,14 @@ void Window::RestoreEnabledIfNecessary() { } } -void Window::AlwaysOnTopChanged() { +void WindowWin::AlwaysOnTopChanged() { ::SetWindowPos(GetNativeView(), is_always_on_top_ ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); } -DWORD Window::CalculateWindowStyle() { +DWORD WindowWin::CalculateWindowStyle() { DWORD window_styles = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | WS_CAPTION; bool can_resize = window_delegate_->CanResize(); @@ -1087,7 +1127,7 @@ DWORD Window::CalculateWindowStyle() { return window_styles; } -DWORD Window::CalculateWindowExStyle() { +DWORD WindowWin::CalculateWindowExStyle() { DWORD window_ex_styles = 0; if (window_delegate_->AsDialogDelegate()) window_ex_styles |= WS_EX_DLGMODALFRAME; @@ -1096,7 +1136,7 @@ DWORD Window::CalculateWindowExStyle() { return window_ex_styles; } -void Window::SaveWindowPosition() { +void WindowWin::SaveWindowPosition() { // The window delegate does the actual saving for us. It seems like (judging // by go/crash) that in some circumstances we can end up here after // WM_DESTROY, at which point the window delegate is likely gone. So just @@ -1116,18 +1156,18 @@ void Window::SaveWindowPosition() { gfx::Rect(win_placement.rcNormalPosition), maximized, is_always_on_top_); } -void Window::LockUpdates() { +void WindowWin::LockUpdates() { lock_updates_ = true; saved_window_style_ = GetWindowLong(GetNativeView(), GWL_STYLE); SetWindowLong(GetNativeView(), GWL_STYLE, saved_window_style_ & ~WS_VISIBLE); } -void Window::UnlockUpdates() { +void WindowWin::UnlockUpdates() { SetWindowLong(GetNativeView(), GWL_STYLE, saved_window_style_); lock_updates_ = false; } -void Window::ResetWindowRegion(bool force) { +void WindowWin::ResetWindowRegion(bool force) { // A native frame uses the native window region, and we don't want to mess // with it. if (non_client_view_->UseNativeFrame()) { @@ -1159,7 +1199,7 @@ void Window::ResetWindowRegion(bool force) { DeleteObject(current_rgn); } -void Window::ProcessNCMousePress(const CPoint& point, int flags) { +void WindowWin::ProcessNCMousePress(const CPoint& point, int flags) { CPoint temp = point; MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1); UINT message_flags = 0; @@ -1171,7 +1211,7 @@ void Window::ProcessNCMousePress(const CPoint& point, int flags) { ProcessMousePressed(temp, message_flags, false); } -LRESULT Window::CallDefaultNCActivateHandler(BOOL active) { +LRESULT WindowWin::CallDefaultNCActivateHandler(BOOL active) { // The DefWindowProc handling for WM_NCACTIVATE renders the classic-look // window title bar directly, so we need to use a redraw lock here to prevent // it from doing so. @@ -1179,7 +1219,7 @@ LRESULT Window::CallDefaultNCActivateHandler(BOOL active) { return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); } -void Window::InitClass() { +void WindowWin::InitClass() { static bool initialized = false; if (!initialized) { resize_cursors_[RC_NORMAL] = LoadCursor(NULL, IDC_ARROW); diff --git a/chrome/views/window_win.h b/chrome/views/window_win.h new file mode 100644 index 0000000..bd6f5ac --- /dev/null +++ b/chrome/views/window_win.h @@ -0,0 +1,278 @@ +// 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. + +#ifndef CHROME_VIEWS_WINDOW_WIN_H__ +#define CHROME_VIEWS_WINDOW_WIN_H__ + +#include "chrome/common/notification_registrar.h" +#include "chrome/views/client_view.h" +#include "chrome/views/non_client_view.h" +#include "chrome/views/widget_win.h" +#include "chrome/views/window.h" + +namespace gfx { +class Point; +class Size; +}; + +namespace views { + +class Client; +class WindowDelegate; + +/////////////////////////////////////////////////////////////////////////////// +// +// WindowWin +// +// A WindowWin is a WidgetWin that has a caption and a border. The frame is +// rendered by the operating system. +// +/////////////////////////////////////////////////////////////////////////////// +class WindowWin : public WidgetWin, + public Window, + public NotificationObserver { + public: + virtual ~WindowWin(); + + // Show the window with the specified show command. + void Show(int show_state); + + // Retrieve the show state of the window. This is one of the SW_SHOW* flags + // passed into Windows' ShowWindow method. For normal windows this defaults + // to SW_SHOWNORMAL, however windows (e.g. the main window) can override this + // method to provide different values (e.g. retrieve the user's specified + // show state from the shortcut starutp info). + virtual int GetShowState() const; + + // Executes the specified SC_command. + void ExecuteSystemMenuCommand(int command); + + // Accessors and setters for various properties. + HWND owning_window() const { return owning_hwnd_; } + void set_focus_on_creation(bool focus_on_creation) { + focus_on_creation_ = focus_on_creation; + } + void set_force_hidden(bool force_hidden) { force_hidden_ = force_hidden; } + + // Window overrides: + virtual gfx::Rect GetBounds() const; + virtual void SetBounds(const gfx::Rect& bounds); + virtual void SetBounds(const gfx::Rect& bounds, + gfx::NativeWindow other_window); + virtual void Show(); + virtual void Activate(); + virtual void Close(); + virtual void Maximize(); + virtual void Minimize(); + virtual void Restore(); + virtual bool IsActive() const; + virtual bool IsVisible() const; + virtual bool IsMaximized() const; + virtual bool IsMinimized() const; + virtual void EnableClose(bool enable); + virtual void DisableInactiveRendering(); + virtual void UpdateWindowTitle(); + virtual void UpdateWindowIcon(); + virtual NonClientFrameView* CreateFrameViewForWindow(); + virtual void UpdateFrameAfterFrameChange(); + virtual WindowDelegate* GetDelegate() const; + virtual NonClientView* GetNonClientView() const; + virtual ClientView* GetClientView() const; + virtual gfx::NativeWindow GetNativeWindow() const; + + // NotificationObserver overrides: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + protected: + friend Window; + + // Constructs the WindowWin. |window_delegate| cannot be NULL. + explicit WindowWin(WindowDelegate* window_delegate); + + // Create the Window. + // If parent is NULL, this WindowWin 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); + + // Sizes the window to the default size specified by its ClientView. + virtual void SizeWindowToDefault(); + + // Returns true if the WindowWin is considered to be an "app window" - i.e. + // any window which when it is the last of its type closed causes the + // application to exit. + virtual bool IsAppWindow() const { return false; } + + // Shows the system menu at the specified screen point. + void RunSystemMenu(const gfx::Point& point); + + // Overridden from WidgetWin: + virtual void OnActivate(UINT action, BOOL minimized, HWND window); + virtual void OnActivateApp(BOOL active, DWORD thread_id); + virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, + int keystate); + virtual void OnCommand(UINT notification_code, int command_id, HWND window); + virtual void OnDestroy(); + virtual LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, + LPARAM l_param); + virtual void OnFinalMessage(HWND window); + virtual void OnInitMenu(HMENU menu); + virtual void OnMouseLeave(); + virtual LRESULT OnNCActivate(BOOL active); + virtual LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); + virtual LRESULT OnNCHitTest(const CPoint& point); + virtual void OnNCPaint(HRGN rgn); + virtual void OnNCLButtonDown(UINT ht_component, const CPoint& point); + virtual void OnNCRButtonDown(UINT ht_component, const CPoint& point); + virtual LRESULT OnNCUAHDrawCaption(UINT msg, WPARAM w_param, LPARAM l_param); + virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param); + virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message); + virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); + virtual LRESULT OnSetText(const wchar_t* text); + virtual void OnSize(UINT size_param, const CSize& new_size); + virtual void OnSysCommand(UINT notification_code, CPoint click); + virtual void OnWindowPosChanging(WINDOWPOS* window_pos); + virtual Window* AsWindow() { return this; } + virtual const Window* AsWindow() const { return this; } + + // Accessor for disable_inactive_rendering_. + bool disable_inactive_rendering() const { + return disable_inactive_rendering_; + } + + private: + // Set the window as modal (by disabling all the other windows). + void BecomeModal(); + + // Sets-up the focus manager with the view that should have focus when the + // window is shown the first time. If NULL is returned, the focus goes to the + // button if there is one, otherwise the to the Cancel button. + void SetInitialFocus(); + + // Place and size the window when it is created. |create_bounds| are the + // bounds used when the window was created. + void SetInitialBounds(const gfx::Rect& create_bounds); + + // Restore saved always on stop state and add the always on top system menu + // if needed. + void InitAlwaysOnTopState(); + + // Add an item for "Always on Top" to the System Menu. + void AddAlwaysOnTopSystemMenuItem(); + + // If necessary, enables all ancestors. + void RestoreEnabledIfNecessary(); + + // Update the window style to reflect the always on top state. + void AlwaysOnTopChanged(); + + // Calculate the appropriate window styles for this window. + DWORD CalculateWindowStyle(); + DWORD CalculateWindowExStyle(); + + // Asks the delegate if any to save the window's location and size. + void SaveWindowPosition(); + + // Lock or unlock the window from being able to redraw itself in response to + // updates to its invalid region. + class ScopedRedrawLock; + void LockUpdates(); + void UnlockUpdates(); + + // Resets the window region for the current window bounds if necessary. + // If |force| is true, the window region is reset to NULL even for native + // frame windows. + void ResetWindowRegion(bool force); + + // Converts a non-client mouse down message to a regular ChromeViews event + // and handle it. |point| is the mouse position of the message in screen + // coords. |flags| are flags that would be passed with a WM_L/M/RBUTTON* + // message and relate to things like which button was pressed. These are + // combined with flags relating to the current key state. + void ProcessNCMousePress(const CPoint& point, int flags); + + // Calls the default WM_NCACTIVATE handler with the specified activation + // value, safely wrapping the call in a ScopedRedrawLock to prevent frame + // flicker. + LRESULT CallDefaultNCActivateHandler(BOOL active); + + // Static resource initialization. + static void InitClass(); + enum ResizeCursor { + RC_NORMAL = 0, RC_VERTICAL, RC_HORIZONTAL, RC_NESW, RC_NWSE + }; + static HCURSOR resize_cursors_[6]; + + // Our window delegate (see Init method for documentation). + WindowDelegate* window_delegate_; + + // The View that provides the non-client area of the window (title bar, + // window controls, sizing borders etc). To use an implementation other than + // the default, this class must be subclassed and this value set to the + // desired implementation before calling |Init|. + NonClientView* non_client_view_; + + // Whether we should SetFocus() on a newly created window after + // Init(). Defaults to true. + bool focus_on_creation_; + + // We need to save the parent window that spawned us, since GetParent() + // returns NULL for dialogs. + HWND owning_hwnd_; + + // The smallest size the window can be. + CSize minimum_size_; + + // Whether or not the window is modal. This comes from the delegate and is + // cached at Init time to avoid calling back to the delegate from the + // destructor. + bool is_modal_; + + // Whether all ancestors have been enabled. This is only used if is_modal_ is + // true. + bool restored_enabled_; + + // Whether the window is currently always on top. + bool is_always_on_top_; + + // We need to own the text of the menu, the Windows API does not copy it. + std::wstring always_on_top_menu_text_; + + // Set to true if the window is in the process of closing . + bool window_closed_; + + // True when the window should be rendered as active, regardless of whether + // or not it actually is. + bool disable_inactive_rendering_; + + // True if this window is the active top level window. + bool is_active_; + + // True if updates to this window are currently locked. + bool lock_updates_; + + // The window styles of the window before updates were locked. + DWORD saved_window_style_; + + // The saved maximized state for this window. See note in SetInitialBounds + // that explains why we save this. + bool saved_maximized_state_; + + // True if we should prevent attempts to make the window visible when we + // handle WM_WINDOWPOSCHANGING. Some calls like ShowWindow(SW_RESTORE) make + // the window visible in addition to restoring it, when all we want to do is + // restore it. + bool force_hidden_; + + // Hold onto notifications. + NotificationRegistrar notification_registrar_; + + DISALLOW_COPY_AND_ASSIGN(WindowWin); +}; + +} // namespace views + +#endif // CHROME_VIEWS_WINDOW_WIN_H__ |