summaryrefslogtreecommitdiffstats
path: root/views/window
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:24:48 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-09 19:24:48 +0000
commita8a6012b1346f64cec04ce8f4ca592cdae77ec2d (patch)
tree43fea13d2183846b977dedd9606335f7f4283d94 /views/window
parent6faf7b1cc2d797140afd3df1211685307488cfcf (diff)
downloadchromium_src-a8a6012b1346f64cec04ce8f4ca592cdae77ec2d.zip
chromium_src-a8a6012b1346f64cec04ce8f4ca592cdae77ec2d.tar.gz
chromium_src-a8a6012b1346f64cec04ce8f4ca592cdae77ec2d.tar.bz2
Consolidate more into Window:
- inactive rendering disabling tracking - window icon updating BUG=72040 TEST=none Review URL: http://codereview.chromium.org/6650031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r--views/window/custom_frame_view.cc4
-rw-r--r--views/window/custom_frame_view.h25
-rw-r--r--views/window/native_frame_view.cc4
-rw-r--r--views/window/native_frame_view.h15
-rw-r--r--views/window/native_window.h6
-rw-r--r--views/window/native_window_delegate.h3
-rw-r--r--views/window/non_client_view.cc4
-rw-r--r--views/window/non_client_view.h4
-rw-r--r--views/window/window.cc25
-rw-r--r--views/window/window.h13
-rw-r--r--views/window/window_gtk.cc9
-rw-r--r--views/window/window_gtk.h3
-rw-r--r--views/window/window_win.cc77
-rw-r--r--views/window/window_win.h13
14 files changed, 115 insertions, 90 deletions
diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc
index c71a917..4a42c1f 100644
--- a/views/window/custom_frame_view.cc
+++ b/views/window/custom_frame_view.cc
@@ -202,6 +202,10 @@ void CustomFrameView::ResetWindowControls() {
// The close button isn't affected by this constraint.
}
+void CustomFrameView::UpdateWindowIcon() {
+ window_icon_->SchedulePaint();
+}
+
///////////////////////////////////////////////////////////////////////////////
// CustomFrameView, View overrides:
diff --git a/views/window/custom_frame_view.h b/views/window/custom_frame_view.h
index 3c0517a..16f8ace 100644
--- a/views/window/custom_frame_view.h
+++ b/views/window/custom_frame_view.h
@@ -35,22 +35,25 @@ class CustomFrameView : public NonClientFrameView,
explicit CustomFrameView(Window* frame);
virtual ~CustomFrameView();
- // Overridden from views::NonClientFrameView:
- virtual gfx::Rect GetBoundsForClientView() const;
+ // Overridden from NonClientFrameView:
+ virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
- virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
- virtual void EnableClose(bool enable);
- virtual void ResetWindowControls();
+ const gfx::Rect& client_bounds) const OVERRIDE;
+ virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
+ virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask)
+ OVERRIDE;
+ virtual void EnableClose(bool enable) OVERRIDE;
+ virtual void ResetWindowControls() OVERRIDE;
+ virtual void UpdateWindowIcon() OVERRIDE;
// View overrides:
- virtual void OnPaint(gfx::Canvas* canvas);
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
+ virtual void Layout() OVERRIDE;
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
// ButtonListener implementation:
- virtual void ButtonPressed(Button* sender, const views::Event& event);
+ virtual void ButtonPressed(Button* sender, const views::Event& event)
+ OVERRIDE;
private:
// Returns the thickness of the border that makes up the window frame edges.
diff --git a/views/window/native_frame_view.cc b/views/window/native_frame_view.cc
index bcef23a..397b6f3 100644
--- a/views/window/native_frame_view.cc
+++ b/views/window/native_frame_view.cc
@@ -51,6 +51,10 @@ void NativeFrameView::ResetWindowControls() {
// Nothing to do.
}
+void NativeFrameView::UpdateWindowIcon() {
+ // Nothing to do.
+}
+
gfx::Size NativeFrameView::GetPreferredSize() {
gfx::Size pref = frame_->client_view()->GetPreferredSize();
gfx::Rect bounds(0, 0, pref.width(), pref.height());
diff --git a/views/window/native_frame_view.h b/views/window/native_frame_view.h
index 07c125c..ac68ddf 100644
--- a/views/window/native_frame_view.h
+++ b/views/window/native_frame_view.h
@@ -18,17 +18,18 @@ class NativeFrameView : public NonClientFrameView {
virtual ~NativeFrameView();
// NonClientFrameView overrides:
- virtual gfx::Rect GetBoundsForClientView() const;
+ virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
virtual gfx::Rect GetWindowBoundsForClientBounds(
- const gfx::Rect& client_bounds) const;
- virtual int NonClientHitTest(const gfx::Point& point);
+ const gfx::Rect& client_bounds) const OVERRIDE;
+ virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
virtual void GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask);
- virtual void EnableClose(bool enable);
- virtual void ResetWindowControls();
+ gfx::Path* window_mask) OVERRIDE;
+ virtual void EnableClose(bool enable) OVERRIDE;
+ virtual void ResetWindowControls() OVERRIDE;
+ virtual void UpdateWindowIcon() OVERRIDE;
// View overrides:
- virtual gfx::Size GetPreferredSize();
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
private:
// Our containing frame.
diff --git a/views/window/native_window.h b/views/window/native_window.h
index d3c0eb6..f845dc0 100644
--- a/views/window/native_window.h
+++ b/views/window/native_window.h
@@ -36,6 +36,12 @@ class NativeWindow {
// Sets the NativeWindow title.
virtual void SetWindowTitle(const std::wstring& title) = 0;
+ // Sets the Window icons. |window_icon| is a 16x16 icon suitable for use in
+ // a title bar. |app_icon| is a larger size for use in the host environment
+ // app switching UI.
+ virtual void SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) = 0;
+
// Update native accessibility properties on the native window.
virtual void SetAccessibleName(const std::wstring& name) = 0;
virtual void SetAccessibleRole(AccessibilityTypes::Role role) = 0;
diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h
index 711306c..40ccfaf 100644
--- a/views/window/native_window_delegate.h
+++ b/views/window/native_window_delegate.h
@@ -19,6 +19,9 @@ class NativeWindowDelegate {
public:
virtual ~NativeWindowDelegate() {}
+ virtual bool IsInactiveRenderingDisabled() const = 0;
+ virtual void EnableInactiveRendering() = 0;
+
// Returns true if the window is modal.
virtual bool IsModal() const = 0;
diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc
index ec82685..387a431 100644
--- a/views/window/non_client_view.cc
+++ b/views/window/non_client_view.cc
@@ -107,6 +107,10 @@ void NonClientView::ResetWindowControls() {
frame_view_->ResetWindowControls();
}
+void NonClientView::UpdateWindowIcon() {
+ frame_view_->UpdateWindowIcon();
+}
+
void NonClientView::LayoutFrameView() {
// First layout the NonClientFrameView, which determines the size of the
// ClientView...
diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h
index 38fc0b1..f1420a1 100644
--- a/views/window/non_client_view.h
+++ b/views/window/non_client_view.h
@@ -67,6 +67,7 @@ class NonClientFrameView : public View {
gfx::Path* window_mask) = 0;
virtual void EnableClose(bool enable) = 0;
virtual void ResetWindowControls() = 0;
+ virtual void UpdateWindowIcon() = 0;
// Overridden from View:
virtual bool HitTest(const gfx::Point& l) const OVERRIDE;
@@ -194,6 +195,9 @@ class NonClientView : public View {
// when the window is maximized, minimized or restored.
void ResetWindowControls();
+ // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
+ void UpdateWindowIcon();
+
// Get/Set client_view property.
ClientView* client_view() const { return client_view_; }
void set_client_view(ClientView* client_view) {
diff --git a/views/window/window.cc b/views/window/window.cc
index 7e04f78..66826c6 100644
--- a/views/window/window.cc
+++ b/views/window/window.cc
@@ -5,6 +5,7 @@
#include "views/window/window.h"
#include "base/string_util.h"
+#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_font_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
@@ -26,7 +27,8 @@ Window::Window(WindowDelegate* window_delegate)
ALLOW_THIS_IN_INITIALIZER_LIST(
non_client_view_(new NonClientView(this))),
saved_maximized_state_(false),
- minimum_size_(100, 100) {
+ minimum_size_(100, 100),
+ disable_inactive_rendering_(false) {
DCHECK(window_delegate_);
DCHECK(!window_delegate_->window_);
window_delegate_->window_ = this;
@@ -103,6 +105,11 @@ void* Window::GetNativeWindowProperty(const char* name) {
return NULL;
}
+void Window::DisableInactiveRendering() {
+ disable_inactive_rendering_ = true;
+ non_client_view_->DisableInactiveRendering(disable_inactive_rendering_);
+}
+
void Window::Activate() {
}
@@ -171,6 +178,9 @@ void Window::UpdateWindowTitle() {
}
void Window::UpdateWindowIcon() {
+ non_client_view_->UpdateWindowIcon();
+ native_window_->SetWindowIcons(window_delegate_->GetWindowIcon(),
+ window_delegate_->GetWindowAppIcon());
}
void Window::SetIsAlwaysOnTop(bool always_on_top) {
@@ -197,6 +207,15 @@ void Window::FrameTypeChanged() {
////////////////////////////////////////////////////////////////////////////////
// Window, internal::NativeWindowDelegate implementation:
+bool Window::IsInactiveRenderingDisabled() const {
+ return disable_inactive_rendering_;
+}
+
+void Window::EnableInactiveRendering() {
+ disable_inactive_rendering_ = false;
+ non_client_view_->DisableInactiveRendering(false);
+}
+
bool Window::IsModal() const {
return window_delegate_->IsModal();
}
@@ -265,7 +284,9 @@ void Window::SetInitialBounds(const gfx::Rect& bounds) {
// Widget's SetBounds method does not further modify the bounds that are
// passed to it.
- native_window_->AsNativeWidget()->SetBounds(saved_bounds);
+ // TODO(beng): Should be able to call Widget::SetBounds() directly once
+ // Window subclasses Widget.
+ native_window_->AsNativeWidget()->GetWidget()->SetBounds(saved_bounds);
} else {
if (bounds.IsEmpty()) {
// No initial bounds supplied, so size the window to its content and
diff --git a/views/window/window.h b/views/window/window.h
index 9775ed7..dddc21b 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -108,14 +108,13 @@ class Window : public internal::NativeWindowDelegate {
// Decrements the force hidden count, showing the window if we have reached
// the top of the stack. See PushForceHidden.
virtual void PopForceHidden() = 0;
+#endif
// 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.
- // For Gtk use WidgetGtk::make_transient_to_parent.
- virtual void DisableInactiveRendering() = 0;
-#endif
+ void DisableInactiveRendering();
// Activates the window, assuming it already exists and is visible.
virtual void Activate();
@@ -166,7 +165,7 @@ class Window : public internal::NativeWindowDelegate {
void UpdateWindowTitle();
// Tell the window to update its icon from the delegate.
- virtual void UpdateWindowIcon();
+ void UpdateWindowIcon();
// Sets whether or not the window is always-on-top.
virtual void SetIsAlwaysOnTop(bool always_on_top);
@@ -218,6 +217,8 @@ class Window : public internal::NativeWindowDelegate {
}
// Overridden from NativeWindowDelegate:
+ virtual bool IsInactiveRenderingDisabled() const OVERRIDE;
+ virtual void EnableInactiveRendering() OVERRIDE;
virtual bool IsModal() const OVERRIDE;
virtual void OnNativeWindowCreated(const gfx::Rect& bounds) OVERRIDE;
virtual void OnWindowDestroying() OVERRIDE;
@@ -247,6 +248,10 @@ class Window : public internal::NativeWindowDelegate {
// The smallest size the window can be.
gfx::Size minimum_size_;
+ // True when the window should be rendered as active, regardless of whether
+ // or not it actually is.
+ bool disable_inactive_rendering_;
+
DISALLOW_COPY_AND_ASSIGN(Window);
};
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc
index 955ede3..46cce43 100644
--- a/views/window/window_gtk.cc
+++ b/views/window/window_gtk.cc
@@ -203,10 +203,6 @@ void WindowGtk::EnableClose(bool enable) {
gtk_window_set_deletable(GetNativeWindow(), enable);
}
-void WindowGtk::UpdateWindowIcon() {
- // Doesn't matter for chrome os.
-}
-
void WindowGtk::SetIsAlwaysOnTop(bool always_on_top) {
gtk_window_set_keep_above(GetNativeWindow(), always_on_top);
}
@@ -397,6 +393,11 @@ void WindowGtk::SetWindowTitle(const std::wstring& title) {
// We don't have a window title on ChromeOS (right now).
}
+void WindowGtk::SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) {
+ // We don't have window icons on ChromeOS.
+}
+
void WindowGtk::SetAccessibleName(const std::wstring& name) {
}
diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h
index a4b0ab7..6f05cae 100644
--- a/views/window/window_gtk.h
+++ b/views/window/window_gtk.h
@@ -51,7 +51,6 @@ class WindowGtk : public WidgetGtk, public NativeWindow, public Window {
virtual bool IsFullscreen() const;
virtual void SetUseDragFrame(bool use_drag_frame);
virtual void EnableClose(bool enable);
- virtual void UpdateWindowIcon();
virtual void SetIsAlwaysOnTop(bool always_on_top);
virtual NonClientFrameView* CreateFrameViewForWindow();
virtual void UpdateFrameAfterFrameChange();
@@ -79,6 +78,8 @@ class WindowGtk : public WidgetGtk, public NativeWindow, public Window {
virtual void BecomeModal() OVERRIDE;
virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
virtual void SetWindowTitle(const std::wstring& title) OVERRIDE;
+ virtual void SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) OVERRIDE;
virtual void SetAccessibleName(const std::wstring& name) OVERRIDE;
virtual void SetAccessibleRole(AccessibilityTypes::Role role) OVERRIDE;
virtual void SetAccessibleState(AccessibilityTypes::State state) OVERRIDE;
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 767d857..f7c9c8b 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -470,42 +470,6 @@ void WindowWin::EnableClose(bool enable) {
SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
}
-void WindowWin::DisableInactiveRendering() {
- disable_inactive_rendering_ = true;
- GetWindow()->non_client_view()->DisableInactiveRendering(
- disable_inactive_rendering_);
-}
-
-void WindowWin::UpdateWindowIcon() {
- // If the non-client view is rendering its own icon, we need to tell it to
- // repaint.
- GetWindow()->non_client_view()->SchedulePaint();
-
- // Update the native frame's icon. We do this regardless of whether or not
- // the native frame is being used, since this also updates the taskbar, etc.
- SkBitmap icon = GetWindow()->window_delegate()->GetWindowIcon();
- if (!icon.isNull()) {
- HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(icon);
- // We need to make sure to destroy the previous icon, otherwise we'll leak
- // these GDI objects until we crash!
- HICON old_icon = reinterpret_cast<HICON>(
- SendMessage(GetNativeView(), WM_SETICON, ICON_SMALL,
- reinterpret_cast<LPARAM>(windows_icon)));
- if (old_icon)
- DestroyIcon(old_icon);
- }
-
- icon = GetWindow()->window_delegate()->GetWindowAppIcon();
- if (!icon.isNull()) {
- HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(icon);
- HICON old_icon = reinterpret_cast<HICON>(
- SendMessage(GetNativeView(), WM_SETICON, ICON_BIG,
- reinterpret_cast<LPARAM>(windows_icon)));
- if (old_icon)
- DestroyIcon(old_icon);
- }
-}
-
void WindowWin::SetIsAlwaysOnTop(bool always_on_top) {
::SetWindowPos(GetNativeView(),
always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
@@ -588,7 +552,6 @@ WindowWin::WindowWin(WindowDelegate* window_delegate)
restored_enabled_(false),
fullscreen_(false),
window_closed_(false),
- disable_inactive_rendering_(false),
is_active_(false),
lock_updates_(false),
saved_window_style_(0),
@@ -664,8 +627,7 @@ 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.
- disable_inactive_rendering_ = false;
- GetWindow()->non_client_view()->DisableInactiveRendering(false);
+ delegate_->EnableInactiveRendering();
// Update the native frame too, since it could be rendering the non-client
// area.
CallDefaultNCActivateHandler(FALSE);
@@ -818,18 +780,11 @@ LRESULT WindowWin::OnNCActivate(BOOL active) {
GetWindow()->non_client_view()->SchedulePaint();
// If we're active again, we should be allowed to render as inactive, so
- // 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.
+ // tell the non-client view.
+ bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled();
if (IsActive())
- GetWindow()->non_client_view()->DisableInactiveRendering(false);
-
- // Reset the disable inactive rendering state since activation has changed.
- if (disable_inactive_rendering_) {
- disable_inactive_rendering_ = false;
- return CallDefaultNCActivateHandler(TRUE);
- }
- return CallDefaultNCActivateHandler(active);
+ delegate_->EnableInactiveRendering();
+ return CallDefaultNCActivateHandler(inactive_rendering_disabled || active);
}
LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
@@ -1194,6 +1149,28 @@ void WindowWin::SetWindowTitle(const std::wstring& title) {
SetAccessibleName(title);
}
+void WindowWin::SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) {
+ if (!window_icon.isNull()) {
+ HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(window_icon);
+ // We need to make sure to destroy the previous icon, otherwise we'll leak
+ // these GDI objects until we crash!
+ HICON old_icon = reinterpret_cast<HICON>(
+ SendMessage(GetNativeView(), WM_SETICON, ICON_SMALL,
+ reinterpret_cast<LPARAM>(windows_icon)));
+ if (old_icon)
+ DestroyIcon(old_icon);
+ }
+ if (!app_icon.isNull()) {
+ HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(app_icon);
+ HICON old_icon = reinterpret_cast<HICON>(
+ SendMessage(GetNativeView(), WM_SETICON, ICON_BIG,
+ reinterpret_cast<LPARAM>(windows_icon)));
+ if (old_icon)
+ DestroyIcon(old_icon);
+ }
+}
+
void WindowWin::SetAccessibleName(const std::wstring& name) {
base::win::ScopedComPtr<IAccPropServices> pAccPropServices;
HRESULT hr = CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER,
diff --git a/views/window/window_win.h b/views/window/window_win.h
index 5224f1f..fcb7a5d 100644
--- a/views/window/window_win.h
+++ b/views/window/window_win.h
@@ -78,8 +78,6 @@ class WindowWin : public WidgetWin,
virtual bool IsFullscreen() const OVERRIDE;
virtual void SetUseDragFrame(bool use_drag_frame) OVERRIDE;
virtual void EnableClose(bool enable) OVERRIDE;
- virtual void DisableInactiveRendering() OVERRIDE;
- virtual void UpdateWindowIcon() OVERRIDE;
virtual void SetIsAlwaysOnTop(bool always_on_top) OVERRIDE;
virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE;
virtual void UpdateFrameAfterFrameChange() OVERRIDE;
@@ -114,11 +112,6 @@ class WindowWin : public WidgetWin,
// show state from the shortcut starutp info).
virtual int GetShowState() const;
- // Accessor for disable_inactive_rendering_.
- bool disable_inactive_rendering() const {
- return disable_inactive_rendering_;
- }
-
// Overridden from WidgetWin:
virtual void OnActivate(UINT action, BOOL minimized, HWND window) OVERRIDE;
virtual void OnActivateApp(BOOL active, DWORD thread_id) OVERRIDE;
@@ -169,6 +162,8 @@ class WindowWin : public WidgetWin,
virtual void BecomeModal() OVERRIDE;
virtual void CenterWindow(const gfx::Size& size) OVERRIDE;
virtual void SetWindowTitle(const std::wstring& title) OVERRIDE;
+ virtual void SetWindowIcons(const SkBitmap& window_icon,
+ const SkBitmap& app_icon) OVERRIDE;
virtual void SetAccessibleName(const std::wstring& name) OVERRIDE;
virtual void SetAccessibleRole(AccessibilityTypes::Role role) OVERRIDE;
virtual void SetAccessibleState(AccessibilityTypes::State state) OVERRIDE;
@@ -259,10 +254,6 @@ class WindowWin : public WidgetWin,
// 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_;