summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-04 22:46:33 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-04 22:46:33 +0000
commitb32f918b82f78d8330b4e79e9ce000dd926870d2 (patch)
tree1b2d6b8baed4554a5ebd543199ff73f68172ed03 /chrome
parent0b7e42805341699a240997b202d4d23aed4b458b (diff)
downloadchromium_src-b32f918b82f78d8330b4e79e9ce000dd926870d2.zip
chromium_src-b32f918b82f78d8330b4e79e9ce000dd926870d2.tar.gz
chromium_src-b32f918b82f78d8330b4e79e9ce000dd926870d2.tar.bz2
Consolidate constrained window code into a cross platform base class.
BUG=72040 TEST=none Review URL: http://codereview.chromium.org/6735041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80386 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/views/constrained_window_views.cc136
-rw-r--r--chrome/browser/ui/views/constrained_window_views.h77
-rw-r--r--chrome/browser/ui/views/native_constrained_window_win.cc71
-rw-r--r--chrome/chrome_browser.gypi5
4 files changed, 176 insertions, 113 deletions
diff --git a/chrome/browser/ui/views/constrained_window_views.cc b/chrome/browser/ui/views/constrained_window_views.cc
index a0dca54..24ad971 100644
--- a/chrome/browser/ui/views/constrained_window_views.cc
+++ b/chrome/browser/ui/views/constrained_window_views.cc
@@ -27,12 +27,17 @@
#include "ui/gfx/rect.h"
#include "views/controls/button/image_button.h"
#include "views/focus/focus_manager.h"
-#include "views/widget/widget_win.h"
#include "views/window/client_view.h"
+#include "views/window/native_window.h"
#include "views/window/non_client_view.h"
#include "views/window/window_resources.h"
#include "views/window/window_shape.h"
+#include "views/window/window.h"
+
+#if defined(OS_WIN)
+#include "views/widget/widget_win.h"
#include "views/window/window_win.h"
+#endif
using base::TimeDelta;
@@ -200,9 +205,11 @@ class ConstrainedWindowFrameView
gfx::Rect CalculateClientAreaBounds(int width, int height) const;
SkColor GetTitleColor() const {
- return (container_->owner()->profile()->IsOffTheRecord() ||
- !views::WidgetWin::IsAeroGlassEnabled()) ? SK_ColorWHITE
- : SK_ColorBLACK;
+ return container_->owner()->profile()->IsOffTheRecord()
+#if defined(OS_WIN)
+ || !views::WidgetWin::IsAeroGlassEnabled()
+#endif
+ ? SK_ColorWHITE : SK_ColorBLACK;
}
// Loads the appropriate set of WindowResources for the frame view.
@@ -311,7 +318,8 @@ 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_->GetWindow()->client_view()->NonClientHitTest(point);
// See if we're in the sysmenu region. (We check the ClientView first to be
// consistent with OpaqueBrowserFrameView; it's not really necessary here.)
@@ -329,7 +337,7 @@ int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) {
int window_component = GetHTComponentForFrame(point, kFrameBorderThickness,
NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
- container_->window_delegate()->CanResize());
+ container_->GetWindow()->window_delegate()->CanResize());
// Fall back to the caption if no other component matches.
return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
}
@@ -483,8 +491,9 @@ void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) {
}
void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) {
- canvas->DrawStringInt(container_->GetWindowTitle(), *title_font_,
- GetTitleColor(), GetMirroredXForRect(title_bounds_),
+ canvas->DrawStringInt(
+ container_->GetWindow()->window_delegate()->GetWindowTitle(),
+ *title_font_, GetTitleColor(), GetMirroredXForRect(title_bounds_),
title_bounds_.y(), title_bounds_.width(), title_bounds_.height());
}
@@ -548,7 +557,9 @@ void ConstrainedWindowFrameView::InitWindowResources() {
void ConstrainedWindowFrameView::InitClass() {
static bool initialized = false;
if (!initialized) {
+#if defined(OS_WIN)
title_font_ = new gfx::Font(views::WindowWin::GetWindowTitleFont());
+#endif
initialized = true;
}
}
@@ -556,31 +567,35 @@ void ConstrainedWindowFrameView::InitClass() {
////////////////////////////////////////////////////////////////////////////////
// ConstrainedWindowViews, public:
-ConstrainedWindowViews::~ConstrainedWindowViews() {
+ConstrainedWindowViews::ConstrainedWindowViews(
+ TabContents* owner,
+ views::WindowDelegate* window_delegate)
+ : owner_(owner),
+ ALLOW_THIS_IN_INITIALIZER_LIST(native_constrained_window_(
+ NativeConstrainedWindow::CreateNativeConstrainedWindow(
+ this, window_delegate))) {
+ GetWindow()->non_client_view()->SetFrameView(CreateFrameViewForWindow());
+ native_constrained_window_->InitNativeConstrainedWindow(
+ owner->GetNativeView());
}
-////////////////////////////////////////////////////////////////////////////////
-// ConstrainedWindowViews, ConstrainedWindow implementation:
-
-views::NonClientFrameView* ConstrainedWindowViews::CreateFrameViewForWindow() {
- return new ConstrainedWindowFrameView(this);
+ConstrainedWindowViews::~ConstrainedWindowViews() {
}
-void ConstrainedWindowViews::FocusConstrainedWindow() {
- if ((!owner_->delegate() ||
- owner_->delegate()->ShouldFocusConstrainedWindow()) &&
- window_delegate() && window_delegate()->GetInitiallyFocusedView()) {
- window_delegate()->GetInitiallyFocusedView()->RequestFocus();
- }
+views::Window* ConstrainedWindowViews::GetWindow() {
+ return native_constrained_window_->AsNativeWindow()->GetWindow();
}
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindowViews, ConstrainedWindow implementation:
+
void ConstrainedWindowViews::ShowConstrainedWindow() {
// We marked the view as hidden during construction. Mark it as
// visible now so FocusManager will let us receive focus.
- non_client_view()->SetVisible(true);
+ GetWindow()->non_client_view()->SetVisible(true);
if (owner_->delegate())
owner_->delegate()->WillShowConstrainedWindow(owner_);
- ActivateConstrainedWindow();
+ GetWindow()->Activate();
FocusConstrainedWindow();
}
@@ -591,80 +606,41 @@ void ConstrainedWindowViews::CloseConstrainedWindow() {
NotificationService::current()->Notify(NotificationType::CWINDOW_CLOSED,
Source<ConstrainedWindow>(this),
NotificationService::NoDetails());
-
- Window::CloseWindow();
-}
-
-std::wstring ConstrainedWindowViews::GetWindowTitle() const {
- if (window_delegate())
- return window_delegate()->GetWindowTitle();
-
- // TODO(pkasting): Shouldn't this be using a localized string, or else calling
- // NOTREACHED()?
- return std::wstring(L"Untitled");
-}
-
-const gfx::Rect& ConstrainedWindowViews::GetCurrentBounds() const {
- return current_bounds_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// ConstrainedWindowViews, private:
-
-ConstrainedWindowViews::ConstrainedWindowViews(
- TabContents* owner,
- views::WindowDelegate* window_delegate)
- : WindowWin(window_delegate),
- owner_(owner) {
- non_client_view()->SetFrameView(CreateFrameViewForWindow());
-
- set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION |
- WS_THICKFRAME | WS_SYSMENU);
- set_focus_on_creation(false);
- // Views default to visible. Since we are creating a window that is
- // not visible (no WS_VISIBLE), mark our View as hidden so that
- // FocusManager can deal with it properly.
- non_client_view()->SetVisible(false);
-
- WindowWin::Init(owner_->GetNativeView(), gfx::Rect());
+ GetWindow()->CloseWindow();
}
-void ConstrainedWindowViews::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);
+void ConstrainedWindowViews::FocusConstrainedWindow() {
+ if ((!owner_->delegate() ||
+ owner_->delegate()->ShouldFocusConstrainedWindow()) &&
+ GetWindow()->window_delegate() &&
+ GetWindow()->window_delegate()->GetInitiallyFocusedView()) {
+ GetWindow()->window_delegate()->GetInitiallyFocusedView()->RequestFocus();
+ }
}
////////////////////////////////////////////////////////////////////////////////
-// ConstrainedWindowViews, views::WidgetWin overrides:
+// ConstrainedWindowViews, NativeConstrainedWindowDelegate implementation:
-void ConstrainedWindowViews::OnFinalMessage(HWND window) {
+void ConstrainedWindowViews::OnNativeConstrainedWindowDestroyed() {
// Tell our constraining TabContents that we've gone so it can update its
// list.
owner_->WillClose(this);
-
- WindowWin::OnFinalMessage(window);
}
-LRESULT ConstrainedWindowViews::OnMouseActivate(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- // We only detach the window if the user clicked on the title bar. That
- // way, users can click inside the contents of legitimate popups obtained
- // with a mouse gesture.
- UINT hittest_code = static_cast<UINT>(LOWORD(l_param));
- if (hittest_code != HTCLIENT && hittest_code != HTNOWHERE &&
- hittest_code != HTCLOSE) {
- ActivateConstrainedWindow();
- }
+void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() {
+ GetWindow()->Activate();
+}
- return MA_ACTIVATE;
+views::NonClientFrameView* ConstrainedWindowViews::CreateFrameViewForWindow() {
+ return new ConstrainedWindowFrameView(this);
}
+////////////////////////////////////////////////////////////////////////////////
+// ConstrainedWindow, public:
+
// static
ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog(
TabContents* parent,
views::WindowDelegate* window_delegate) {
- ConstrainedWindowViews* window = new ConstrainedWindowViews(parent,
- window_delegate);
- return window;
+ return new ConstrainedWindowViews(parent, window_delegate);
}
diff --git a/chrome/browser/ui/views/constrained_window_views.h b/chrome/browser/ui/views/constrained_window_views.h
index 473409e..0d3f4db 100644
--- a/chrome/browser/ui/views/constrained_window_views.h
+++ b/chrome/browser/ui/views/constrained_window_views.h
@@ -6,18 +6,53 @@
#define CHROME_BROWSER_UI_VIEWS_CONSTRAINED_WINDOW_VIEWS_H_
#pragma once
+#include "base/compiler_specific.h"
#include "content/browser/tab_contents/constrained_window.h"
-#include "content/browser/tab_contents/tab_contents_delegate.h"
+#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
-#include "views/window/window_win.h"
class ConstrainedTabContentsWindowDelegate;
class ConstrainedWindowAnimation;
class ConstrainedWindowFrameView;
namespace views {
+class NativeWindow;
+class NonClientFrameView;
+class Window;
class WindowDelegate;
}
+class NativeConstrainedWindowDelegate {
+ public:
+ virtual ~NativeConstrainedWindowDelegate() {}
+
+ // Called after the NativeConstrainedWindow has been destroyed and is about to
+ // be deleted.
+ virtual void OnNativeConstrainedWindowDestroyed() = 0;
+
+ // Called when the NativeConstrainedWindow is clicked on when inactive.
+ virtual void OnNativeConstrainedWindowMouseActivate() = 0;
+
+ // Creates the frame view for the constrained window.
+ // TODO(beng): remove once ConstrainedWindowViews is-a views::Window.
+ virtual views::NonClientFrameView* CreateFrameViewForWindow() = 0;
+};
+
+class NativeConstrainedWindow {
+ public:
+ virtual ~NativeConstrainedWindow() {}
+
+ // Creates a platform-specific implementation of NativeConstrainedWindow.
+ // TODO(beng): Remove WindowDelegate param once ConstrainedWindowViews is-a
+ // views::Window.
+ static NativeConstrainedWindow* CreateNativeConstrainedWindow(
+ NativeConstrainedWindowDelegate* delegate,
+ views::WindowDelegate* window_delegate);
+
+ virtual void InitNativeConstrainedWindow(gfx::NativeView parent) = 0;
+
+ virtual views::NativeWindow* AsNativeWindow() = 0;
+};
+
///////////////////////////////////////////////////////////////////////////////
// ConstrainedWindowViews
//
@@ -25,52 +60,32 @@ class WindowDelegate;
// a child HWND with a custom window frame.
//
class ConstrainedWindowViews : public ConstrainedWindow,
- public views::WindowWin {
+ public NativeConstrainedWindowDelegate {
public:
+ ConstrainedWindowViews(TabContents* owner,
+ views::WindowDelegate* window_delegate);
virtual ~ConstrainedWindowViews();
// Returns the TabContents that constrains this Constrained Window.
TabContents* owner() const { return owner_; }
- // Overridden from views::Window:
- virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE;
+ views::Window* GetWindow();
// Overridden from ConstrainedWindow:
virtual void ShowConstrainedWindow() OVERRIDE;
virtual void CloseConstrainedWindow() OVERRIDE;
virtual void FocusConstrainedWindow() OVERRIDE;
- virtual std::wstring GetWindowTitle() const;
- virtual const gfx::Rect& GetCurrentBounds() const;
-
- protected:
- // Windows message handlers:
- virtual void OnFinalMessage(HWND window) OVERRIDE;
- virtual LRESULT OnMouseActivate(UINT message,
- WPARAM w_param,
- LPARAM l_param) OVERRIDE;
-
private:
- friend class ConstrainedWindow;
-
- // Use the static factory methods on ConstrainedWindow to construct a
- // ConstrainedWindow.
- ConstrainedWindowViews(TabContents* owner,
- views::WindowDelegate* window_delegate);
-
- // Moves this window to the front of the Z-order and registers us with the
- // focus manager.
- void ActivateConstrainedWindow();
+ // Overridden from NativeConstrainedWindowDelegate:
+ virtual void OnNativeConstrainedWindowDestroyed() OVERRIDE;
+ virtual void OnNativeConstrainedWindowMouseActivate() OVERRIDE;
+ virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE;
// The TabContents that owns and constrains this ConstrainedWindow.
TabContents* owner_;
- // Current "anchor point", the lower right point at which we render
- // the constrained title bar.
- gfx::Point anchor_point_;
-
- // Current display rectangle (relative to owner_'s visible area).
- gfx::Rect current_bounds_;
+ NativeConstrainedWindow* native_constrained_window_;
DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowViews);
};
diff --git a/chrome/browser/ui/views/native_constrained_window_win.cc b/chrome/browser/ui/views/native_constrained_window_win.cc
new file mode 100644
index 0000000..96facbe
--- /dev/null
+++ b/chrome/browser/ui/views/native_constrained_window_win.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2011 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.
+
+#include "chrome/browser/ui/views/constrained_window_views.h"
+
+#include "views/window/window_win.h"
+
+namespace {
+bool IsNonClientHitTestCode(UINT hittest) {
+ return hittest != HTCLIENT && hittest != HTNOWHERE && hittest != HTCLOSE;
+}
+}
+
+class NativeConstrainedWindowWin : public NativeConstrainedWindow,
+ public views::WindowWin {
+ public:
+ NativeConstrainedWindowWin(NativeConstrainedWindowDelegate* delegate,
+ views::WindowDelegate* window_delegate)
+ : WindowWin(window_delegate),
+ delegate_(delegate) {
+ views::Widget::CreateParams params(
+ views::Widget::CreateParams::TYPE_WINDOW);
+ params.child = true;
+ SetCreateParams(params);
+ }
+
+ virtual ~NativeConstrainedWindowWin() {
+ }
+
+ private:
+ // Overridden from NativeConstrainedWindow:
+ virtual void InitNativeConstrainedWindow(gfx::NativeView parent) OVERRIDE {
+ WindowWin::Init(parent, gfx::Rect());
+ }
+ virtual views::NativeWindow* AsNativeWindow() OVERRIDE {
+ return this;
+ }
+
+ // Overridden from views::WindowWin:
+ virtual void OnFinalMessage(HWND window) OVERRIDE {
+ delegate_->OnNativeConstrainedWindowDestroyed();
+ WindowWin::OnFinalMessage(window);
+ }
+ virtual LRESULT OnMouseActivate(UINT message,
+ WPARAM w_param,
+ LPARAM l_param) OVERRIDE {
+ if (IsNonClientHitTestCode(static_cast<UINT>(LOWORD(l_param))))
+ delegate_->OnNativeConstrainedWindowMouseActivate();
+ return WindowWin::OnMouseActivate(message, w_param, l_param);
+ }
+
+ // Overridden from views::Window:
+ virtual views::NonClientFrameView* CreateFrameViewForWindow() OVERRIDE {
+ return delegate_->CreateFrameViewForWindow();
+ }
+
+ NativeConstrainedWindowDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeConstrainedWindowWin);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeConstrainedWindow, public:
+
+// static
+NativeConstrainedWindow* NativeConstrainedWindow::CreateNativeConstrainedWindow(
+ NativeConstrainedWindowDelegate* delegate,
+ views::WindowDelegate* window_delegate) {
+ return new NativeConstrainedWindowWin(delegate, window_delegate);
+}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 751fe32..d25a5fb 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2836,8 +2836,8 @@
'browser/ui/views/dialog_stubs_gtk.cc',
'browser/ui/views/dom_view.cc',
'browser/ui/views/dom_view.h',
- 'browser/ui/views/download_in_progress_dialog_view.cc',
- 'browser/ui/views/download_in_progress_dialog_view.h',
+ 'browser/ui/views/download_in_progress_dialog_view.cc',
+ 'browser/ui/views/download_in_progress_dialog_view.h',
'browser/ui/views/download_item_view.cc',
'browser/ui/views/download_item_view.h',
'browser/ui/views/download_shelf_view.cc',
@@ -2984,6 +2984,7 @@
'browser/ui/views/location_bar/suggested_text_view.h',
'browser/ui/views/login_view.cc',
'browser/ui/views/login_view.h',
+ 'browser/ui/views/native_constrained_window_win.cc',
'browser/ui/views/notifications/balloon_view.cc',
'browser/ui/views/notifications/balloon_view.h',
'browser/ui/views/notifications/balloon_view_host.cc',