Commit c0495e88 authored by ben@chromium.org's avatar ben@chromium.org

Revert 152098 - Landing this again to get more information about the crashes....

Revert 152098 - Landing this again to get more information about the crashes. Doesn't crash locally or on the trybots it seems.

Move more message handlers from NativeWidgetWin to HWNDMessageHandler.

http://crbug.com/142962
R=sky@chromium.org

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=152013
Review URL: https://chromiumcodereview.appspot.com/10832345

TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10854205

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152113 0039d316-1c4b-4281-b951-d872f2087c98
parent 15bcb340
...@@ -4,12 +4,6 @@ ...@@ -4,12 +4,6 @@
#include "ui/views/widget/hwnd_message_handler.h" #include "ui/views/widget/hwnd_message_handler.h"
#include <dwmapi.h>
#include "base/system_monitor/system_monitor.h"
#include "ui/base/native_theme/native_theme_win.h"
#include "ui/gfx/path.h"
#include "ui/views/ime/input_method_win.h"
#include "ui/views/widget/hwnd_message_handler_delegate.h" #include "ui/views/widget/hwnd_message_handler_delegate.h"
#include "ui/views/widget/native_widget_win.h" #include "ui/views/widget/native_widget_win.h"
...@@ -119,263 +113,9 @@ void HWNDMessageHandler::OnExitSizeMove() { ...@@ -119,263 +113,9 @@ void HWNDMessageHandler::OnExitSizeMove() {
SetMsgHandled(FALSE); SetMsgHandled(FALSE);
} }
LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
WPARAM w_param,
LPARAM l_param) {
InputMethod* input_method = delegate_->GetInputMethod();
if (!input_method || input_method->IsMock()) {
SetMsgHandled(FALSE);
return 0;
}
InputMethodWin* ime_win = static_cast<InputMethodWin*>(input_method);
BOOL handled = FALSE;
LRESULT result = ime_win->OnImeMessages(message, w_param, l_param, &handled);
SetMsgHandled(handled);
return result;
}
void HWNDMessageHandler::OnInitMenu(HMENU menu) {
bool is_fullscreen = delegate_->AsNativeWidgetWin()->IsFullscreen();
bool is_minimized = delegate_->AsNativeWidgetWin()->IsMinimized();
bool is_maximized = delegate_->AsNativeWidgetWin()->IsMaximized();
bool is_restored = !is_fullscreen && !is_minimized && !is_maximized;
EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized);
EnableMenuItem(menu, SC_MOVE, is_restored);
EnableMenuItem(menu, SC_SIZE, delegate_->CanResize() && is_restored);
EnableMenuItem(menu, SC_MAXIMIZE, delegate_->CanMaximize() &&
!is_fullscreen && !is_maximized);
EnableMenuItem(menu, SC_MINIMIZE, delegate_->CanMaximize() && !is_minimized);
}
void HWNDMessageHandler::OnInitMenuPopup() {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnInputLangChange(DWORD character_set,
HKL input_language_id) {
InputMethod* input_method = delegate_->GetInputMethod();
if (input_method && !input_method->IsMock()) {
static_cast<InputMethodWin*>(input_method)->OnInputLangChange(
character_set, input_language_id);
}
}
LRESULT HWNDMessageHandler::OnKeyEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param };
ui::KeyEvent key(msg, message == WM_CHAR);
InputMethod* input_method = delegate_->GetInputMethod();
if (input_method)
input_method->DispatchKeyEvent(key);
else
delegate_->AsNativeWidgetWin()->DispatchKeyEventPostIME(key);
return 0;
}
void HWNDMessageHandler::OnKillFocus(HWND focused_window) {
delegate_->HandleNativeBlur(focused_window);
InputMethod* input_method = delegate_->GetInputMethod();
if (input_method)
input_method->OnBlur();
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnMouseActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
// TODO(beng): resolve this with the GetWindowLong() check on the subsequent
// line.
if (delegate_->IsWidgetWindow())
return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT;
if (delegate_->AsNativeWidgetWin()->GetWindowLong(GWL_EXSTYLE) &
WS_EX_NOACTIVATE) {
return MA_NOACTIVATE;
}
SetMsgHandled(FALSE);
return MA_ACTIVATE;
}
void HWNDMessageHandler::OnMove(const CPoint& point) {
delegate_->HandleMove();
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) {
delegate_->HandleMove();
}
LRESULT HWNDMessageHandler::OnNCHitTest(const CPoint& point) {
if (!delegate_->IsWidgetWindow()) {
SetMsgHandled(FALSE);
return 0;
}
// If the DWM is rendering the window controls, we need to give the DWM's
// default window procedure first chance to handle hit testing.
if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) {
LRESULT result;
if (DwmDefWindowProc(hwnd(), WM_NCHITTEST, 0,
MAKELPARAM(point.x, point.y), &result)) {
return result;
}
}
// First, give the NonClientView a chance to test the point to see if it
// provides any of the non-client area.
POINT temp = point;
MapWindowPoints(HWND_DESKTOP, hwnd(), &temp, 1);
int component = delegate_->GetNonClientComponent(gfx::Point(temp));
if (component != HTNOWHERE)
return component;
// Otherwise, we let Windows do all the native frame non-client handling for
// us.
SetMsgHandled(FALSE);
return 0;
}
LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message,
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(delegate_->IsUsingCustomFrame());
return 0;
}
LRESULT HWNDMessageHandler::OnNCUAHDrawFrame(UINT message,
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(delegate_->IsUsingCustomFrame());
return 0;
}
LRESULT HWNDMessageHandler::OnPowerBroadcast(DWORD power_event, DWORD data) {
base::SystemMonitor* monitor = base::SystemMonitor::Get();
if (monitor)
monitor->ProcessWmPowerBroadcastMessage(power_event);
SetMsgHandled(FALSE);
return 0;
}
LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message,
WPARAM w_param,
LPARAM l_param) {
SetMsgHandled(FALSE);
return 0;
}
LRESULT HWNDMessageHandler::OnSetCursor(UINT message,
WPARAM w_param,
LPARAM l_param) {
// Using ScopedRedrawLock here frequently allows content behind this window to
// paint in front of this window, causing glaring rendering artifacts.
// If omitting ScopedRedrawLock here triggers caption rendering artifacts via
// DefWindowProc message handling, we'll need to find a better solution.
SetMsgHandled(FALSE);
return 0;
}
void HWNDMessageHandler::OnSetFocus(HWND last_focused_window) {
delegate_->HandleNativeFocus(last_focused_window);
InputMethod* input_method = delegate_->GetInputMethod();
if (input_method)
input_method->OnFocus();
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnSetIcon(UINT size_type, HICON new_icon) {
// Use a ScopedRedrawLock to avoid weird non-client painting.
return DefWindowProcWithRedrawLock(WM_SETICON, size_type,
reinterpret_cast<LPARAM>(new_icon));
}
LRESULT HWNDMessageHandler::OnSetText(const wchar_t* text) {
// Use a ScopedRedrawLock to avoid weird non-client painting.
return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL,
reinterpret_cast<LPARAM>(text));
}
void HWNDMessageHandler::OnSize(UINT param, const CSize& size) {
RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
// ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
// invoked OnSize we ensure the RootView has been laid out.
ResetWindowRegion(false);
}
void HWNDMessageHandler::OnThemeChanged() {
ui::NativeThemeWin::instance()->CloseHandles();
}
void HWNDMessageHandler::OnVScroll(int scroll_type,
short position,
HWND scrollbar) {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::ResetWindowRegion(bool force) {
// A native frame uses the native window region, and we don't want to mess
// with it.
if (!delegate_->IsUsingCustomFrame() || !delegate_->IsWidgetWindow()) {
if (force)
SetWindowRgn(hwnd(), NULL, TRUE);
return;
}
// Changing the window region is going to force a paint. Only change the
// window region if the region really differs.
HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
int current_rgn_result = GetWindowRgn(hwnd(), current_rgn);
CRect window_rect;
GetWindowRect(hwnd(), &window_rect);
HRGN new_region;
if (delegate_->AsNativeWidgetWin()->IsMaximized()) {
HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof mi;
GetMonitorInfo(monitor, &mi);
CRect work_rect = mi.rcWork;
work_rect.OffsetRect(-window_rect.left, -window_rect.top);
new_region = CreateRectRgnIndirect(&work_rect);
} else {
gfx::Path window_mask;
delegate_->GetWindowMask(
gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask);
new_region = window_mask.CreateNativeRegion();
}
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
// SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
SetWindowRgn(hwnd(), new_region, TRUE);
} else {
DeleteObject(new_region);
}
DeleteObject(current_rgn);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, private: // HWNDMessageHandler, private:
HWND HWNDMessageHandler::hwnd() {
return delegate_->AsNativeWidgetWin()->hwnd();
}
LRESULT HWNDMessageHandler::DefWindowProcWithRedrawLock(UINT message,
WPARAM w_param,
LPARAM l_param) {
return delegate_->AsNativeWidgetWin()->DefWindowProcWithRedrawLock(message,
w_param,
l_param);
}
void HWNDMessageHandler::SetMsgHandled(BOOL handled) { void HWNDMessageHandler::SetMsgHandled(BOOL handled) {
delegate_->AsNativeWidgetWin()->SetMsgHandled(handled); delegate_->AsNativeWidgetWin()->SetMsgHandled(handled);
} }
......
...@@ -48,27 +48,6 @@ class VIEWS_EXPORT HWNDMessageHandler { ...@@ -48,27 +48,6 @@ class VIEWS_EXPORT HWNDMessageHandler {
LRESULT OnEraseBkgnd(HDC dc); LRESULT OnEraseBkgnd(HDC dc);
void OnExitMenuLoop(BOOL is_track_popup_menu); void OnExitMenuLoop(BOOL is_track_popup_menu);
void OnExitSizeMove(); void OnExitSizeMove();
LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param);
void OnInitMenu(HMENU menu);
void OnInitMenuPopup();
void OnInputLangChange(DWORD character_set, HKL input_language_id);
LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param);
void OnKillFocus(HWND focused_window);
LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
void OnMove(const CPoint& point);
void OnMoving(UINT param, const RECT* new_bounds);
LRESULT OnNCHitTest(const CPoint& point);
LRESULT OnNCUAHDrawCaption(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnNCUAHDrawFrame(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnPowerBroadcast(DWORD power_event, DWORD data);
LRESULT OnReflectedMessage(UINT message, WPARAM w_param, LPARAM l_param);
LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param);
void OnSetFocus(HWND last_focused_window);
LRESULT OnSetIcon(UINT size_type, HICON new_icon);
LRESULT OnSetText(const wchar_t* text);
void OnSize(UINT param, const CSize& size);
void OnThemeChanged();
void OnVScroll(int scroll_type, short position, HWND scrollbar);
// TODO(beng): Can be removed once this object becomes the WindowImpl. // TODO(beng): Can be removed once this object becomes the WindowImpl.
bool remove_standard_frame() const { return remove_standard_frame_; } bool remove_standard_frame() const { return remove_standard_frame_; }
...@@ -76,21 +55,7 @@ class VIEWS_EXPORT HWNDMessageHandler { ...@@ -76,21 +55,7 @@ class VIEWS_EXPORT HWNDMessageHandler {
remove_standard_frame_ = remove_standard_frame; remove_standard_frame_ = remove_standard_frame;
} }
// Resets the window region for the current widget bounds if necessary.
// If |force| is true, the window region is reset to NULL even for native
// frame windows.
void ResetWindowRegion(bool force);
private: private:
// TODO(beng): This won't be a style violation once this object becomes the
// WindowImpl.
HWND hwnd();
// TODO(beng): Remove once this class becomes the WindowImpl.
LRESULT DefWindowProcWithRedrawLock(UINT message,
WPARAM w_param,
LPARAM l_param);
// TODO(beng): Remove once this class becomes the WindowImpl. // TODO(beng): Remove once this class becomes the WindowImpl.
void SetMsgHandled(BOOL handled); void SetMsgHandled(BOOL handled);
......
...@@ -7,15 +7,8 @@ ...@@ -7,15 +7,8 @@
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace gfx {
class Path;
class Point;
class Size;
}
namespace views { namespace views {
class InputMethod;
class NativeWidgetWin; class NativeWidgetWin;
// Implemented by the object that uses the HWNDMessageHandler to handle // Implemented by the object that uses the HWNDMessageHandler to handle
...@@ -28,15 +21,6 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate { ...@@ -28,15 +21,6 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
// to avoid confusion. // to avoid confusion.
virtual bool IsUsingCustomFrame() const = 0; virtual bool IsUsingCustomFrame() const = 0;
virtual bool CanResize() const = 0;
virtual bool CanMaximize() const = 0;
virtual bool CanActivate() const = 0;
virtual int GetNonClientComponent(const gfx::Point& point) const = 0;
virtual void GetWindowMask(const gfx::Size& size, gfx::Path* mask) = 0;
virtual InputMethod* GetInputMethod() = 0;
// TODO(beng): Investigate migrating these methods to On* prefixes once // TODO(beng): Investigate migrating these methods to On* prefixes once
// HWNDMessageHandler is the WindowImpl. // HWNDMessageHandler is the WindowImpl.
...@@ -71,15 +55,6 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate { ...@@ -71,15 +55,6 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
virtual void HandleBeginWMSizeMove() = 0; virtual void HandleBeginWMSizeMove() = 0;
virtual void HandleEndWMSizeMove() = 0; virtual void HandleEndWMSizeMove() = 0;
// Called when the window's position changed.
virtual void HandleMove() = 0;
// Called when focus shifted to this HWND from |last_focused_window|.
virtual void HandleNativeFocus(HWND last_focused_window) = 0;
// Called when focus shifted from the HWND to a different window.
virtual void HandleNativeBlur(HWND focused_window) = 0;
// This is provided for methods that need to call private methods on NWW. // This is provided for methods that need to call private methods on NWW.
// TODO(beng): should be removed once HWNDMessageHandler is the WindowImpl. // TODO(beng): should be removed once HWNDMessageHandler is the WindowImpl.
virtual NativeWidgetWin* AsNativeWidgetWin() = 0; virtual NativeWidgetWin* AsNativeWidgetWin() = 0;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/system_monitor/system_monitor.h"
#include "base/win/scoped_gdi_object.h" #include "base/win/scoped_gdi_object.h"
#include "base/win/win_util.h" #include "base/win/win_util.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
...@@ -21,6 +22,7 @@ ...@@ -21,6 +22,7 @@
#include "ui/base/event.h" #include "ui/base/event.h"
#include "ui/base/keycodes/keyboard_code_conversion_win.h" #include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "ui/base/l10n/l10n_util_win.h" #include "ui/base/l10n/l10n_util_win.h"
#include "ui/base/native_theme/native_theme_win.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/base/view_prop.h" #include "ui/base/view_prop.h"
#include "ui/base/win/hwnd_util.h" #include "ui/base/win/hwnd_util.h"
...@@ -544,7 +546,7 @@ NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() { ...@@ -544,7 +546,7 @@ NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() {
void NativeWidgetWin::UpdateFrameAfterFrameChange() { void NativeWidgetWin::UpdateFrameAfterFrameChange() {
// We've either gained or lost a custom window region, so reset it now. // We've either gained or lost a custom window region, so reset it now.
message_handler_->ResetWindowRegion(true); ResetWindowRegion(true);
} }
bool NativeWidgetWin::ShouldUseNativeFrame() const { bool NativeWidgetWin::ShouldUseNativeFrame() const {
...@@ -1456,39 +1458,87 @@ void NativeWidgetWin::OnHScroll(int scroll_type, ...@@ -1456,39 +1458,87 @@ void NativeWidgetWin::OnHScroll(int scroll_type,
LRESULT NativeWidgetWin::OnImeMessages(UINT message, LRESULT NativeWidgetWin::OnImeMessages(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnImeMessages(message, w_param, l_param); InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (!input_method || input_method->IsMock()) {
SetMsgHandled(FALSE);
return 0;
}
InputMethodWin* ime_win = static_cast<InputMethodWin*>(input_method);
BOOL handled = FALSE;
LRESULT result = ime_win->OnImeMessages(message, w_param, l_param, &handled);
SetMsgHandled(handled);
return result;
} }
void NativeWidgetWin::OnInitMenu(HMENU menu) { void NativeWidgetWin::OnInitMenu(HMENU menu) {
bool is_fullscreen = IsFullscreen();
bool is_minimized = IsMinimized();
bool is_maximized = IsMaximized();
bool is_restored = !is_fullscreen && !is_minimized && !is_maximized;
ScopedRedrawLock lock(this); ScopedRedrawLock lock(this);
message_handler_->OnInitMenu(menu); EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized);
EnableMenuItem(menu, SC_MOVE, is_restored);
EnableMenuItem(menu, SC_SIZE,
GetWidget()->widget_delegate()->CanResize() && is_restored);
EnableMenuItem(menu, SC_MAXIMIZE,
GetWidget()->widget_delegate()->CanMaximize() &&
!is_fullscreen && !is_maximized);
EnableMenuItem(menu, SC_MINIMIZE,
GetWidget()->widget_delegate()->CanMaximize() &&
!is_minimized);
} }
void NativeWidgetWin::OnInitMenuPopup(HMENU menu, void NativeWidgetWin::OnInitMenuPopup(HMENU menu,
UINT position, UINT position,
BOOL is_system_menu) { BOOL is_system_menu) {
message_handler_->OnInitMenu(menu); SetMsgHandled(FALSE);
} }
void NativeWidgetWin::OnInputLangChange(DWORD character_set, void NativeWidgetWin::OnInputLangChange(DWORD character_set,
HKL input_language_id) { HKL input_language_id) {
message_handler_->OnInputLangChange(character_set, input_language_id); InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method && !input_method->IsMock()) {
static_cast<InputMethodWin*>(input_method)->OnInputLangChange(
character_set, input_language_id);
}
} }
LRESULT NativeWidgetWin::OnKeyEvent(UINT message, LRESULT NativeWidgetWin::OnKeyEvent(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnKeyEvent(message, w_param, l_param); MSG msg = { hwnd(), message, w_param, l_param };
ui::KeyEvent key(msg, message == WM_CHAR);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->DispatchKeyEvent(key);
else
DispatchKeyEventPostIME(key);
return 0;
} }
void NativeWidgetWin::OnKillFocus(HWND focused_window) { void NativeWidgetWin::OnKillFocus(HWND focused_window) {
message_handler_->OnKillFocus(focused_window); delegate_->OnNativeBlur(focused_window);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->OnBlur();
SetMsgHandled(FALSE);
} }
LRESULT NativeWidgetWin::OnMouseActivate(UINT message, LRESULT NativeWidgetWin::OnMouseActivate(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnMouseActivate(message, w_param, l_param); // TODO(beng): resolve this with the GetWindowLong() check on the subsequent
// line.
if (GetWidget()->non_client_view())
return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT;
if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)
return MA_NOACTIVATE;
SetMsgHandled(FALSE);
return MA_ACTIVATE;
} }
LRESULT NativeWidgetWin::OnMouseRange(UINT message, LRESULT NativeWidgetWin::OnMouseRange(UINT message,
...@@ -1583,11 +1633,12 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message, ...@@ -1583,11 +1633,12 @@ LRESULT NativeWidgetWin::OnMouseRange(UINT message,
} }
void NativeWidgetWin::OnMove(const CPoint& point) { void NativeWidgetWin::OnMove(const CPoint& point) {
message_handler_->OnMove(point); delegate_->OnNativeWidgetMove();
SetMsgHandled(FALSE);
} }
void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) { void NativeWidgetWin::OnMoving(UINT param, const LPRECT new_bounds) {
message_handler_->OnMoving(param, new_bounds); delegate_->OnNativeWidgetMove();
} }
LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { LRESULT NativeWidgetWin::OnNCActivate(BOOL active) {
...@@ -1722,7 +1773,34 @@ LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { ...@@ -1722,7 +1773,34 @@ LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
} }
LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) { LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) {
return message_handler_->OnNCHitTest(point); if (!GetWidget()->non_client_view()) {
SetMsgHandled(FALSE);
return 0;
}
// If the DWM is rendering the window controls, we need to give the DWM's
// default window procedure first chance to handle hit testing.
if (!message_handler_->remove_standard_frame() &&
GetWidget()->ShouldUseNativeFrame()) {
LRESULT result;
if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
MAKELPARAM(point.x, point.y), &result)) {
return result;
}
}
// First, give the NonClientView a chance to test the point to see if it
// provides any of the non-client area.
POINT temp = point;
MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1);
int component = delegate_->GetNonClientComponent(gfx::Point(temp));
if (component != HTNOWHERE)
return component;
// Otherwise, we let Windows do all the native frame non-client handling for
// us.
SetMsgHandled(FALSE);
return 0;
} }
void NativeWidgetWin::OnNCPaint(HRGN rgn) { void NativeWidgetWin::OnNCPaint(HRGN rgn) {
...@@ -1810,13 +1888,19 @@ void NativeWidgetWin::OnNCPaint(HRGN rgn) { ...@@ -1810,13 +1888,19 @@ void NativeWidgetWin::OnNCPaint(HRGN rgn) {
LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg, LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT msg,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnNCUAHDrawCaption(msg, w_param, 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(!GetWidget()->ShouldUseNativeFrame());
return 0;
} }
LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg, LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT msg,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnNCUAHDrawFrame(msg, w_param, 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(!GetWidget()->ShouldUseNativeFrame());
return 0;
} }
LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) {
...@@ -1854,31 +1938,49 @@ void NativeWidgetWin::OnPaint(HDC dc) { ...@@ -1854,31 +1938,49 @@ void NativeWidgetWin::OnPaint(HDC dc) {
} }
LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) {
return message_handler_->OnPowerBroadcast(power_event, data); base::SystemMonitor* monitor = base::SystemMonitor::Get();
if (monitor)
monitor->ProcessWmPowerBroadcastMessage(power_event);
SetMsgHandled(FALSE);
return 0;
} }
LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg, LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnReflectedMessage(msg, w_param, l_param); SetMsgHandled(FALSE);
return 0;
} }
LRESULT NativeWidgetWin::OnSetCursor(UINT message, LRESULT NativeWidgetWin::OnSetCursor(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
return message_handler_->OnSetCursor(message, w_param, l_param); // Using ScopedRedrawLock here frequently allows content behind this window to
// paint in front of this window, causing glaring rendering artifacts.
// If omitting ScopedRedrawLock here triggers caption rendering artifacts via
// DefWindowProc message handling, we'll need to find a better solution.
SetMsgHandled(FALSE);
return 0;
} }
void NativeWidgetWin::OnSetFocus(HWND old_focused_window) { void NativeWidgetWin::OnSetFocus(HWND old_focused_window) {
message_handler_->OnSetFocus(old_focused_window); delegate_->OnNativeFocus(old_focused_window);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->OnFocus();
SetMsgHandled(FALSE);
} }
LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) {
return message_handler_->OnSetIcon(size_type, new_icon); // Use a ScopedRedrawLock to avoid weird non-client painting.
return DefWindowProcWithRedrawLock(WM_SETICON, size_type,
reinterpret_cast<LPARAM>(new_icon));
} }
LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) {
return message_handler_->OnSetText(text); // Use a ScopedRedrawLock to avoid weird non-client painting.
return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL,
reinterpret_cast<LPARAM>(text));
} }
void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
...@@ -1898,7 +2000,10 @@ void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { ...@@ -1898,7 +2000,10 @@ void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
} }
void NativeWidgetWin::OnSize(UINT param, const CSize& size) { void NativeWidgetWin::OnSize(UINT param, const CSize& size) {
message_handler_->OnSize(param, size); RedrawWindow(GetNativeView(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
// ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
// invoked OnSize we ensure the RootView has been laid out.
ResetWindowRegion(false);
} }
void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) {
...@@ -1953,7 +2058,8 @@ void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { ...@@ -1953,7 +2058,8 @@ void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) {
} }
void NativeWidgetWin::OnThemeChanged() { void NativeWidgetWin::OnThemeChanged() {
message_handler_->OnThemeChanged(); // Notify NativeThemeWin.
ui::NativeThemeWin::instance()->CloseHandles();
} }
LRESULT NativeWidgetWin::OnTouchEvent(UINT message, LRESULT NativeWidgetWin::OnTouchEvent(UINT message,
...@@ -1978,7 +2084,7 @@ LRESULT NativeWidgetWin::OnTouchEvent(UINT message, ...@@ -1978,7 +2084,7 @@ LRESULT NativeWidgetWin::OnTouchEvent(UINT message,
void NativeWidgetWin::OnVScroll(int scroll_type, void NativeWidgetWin::OnVScroll(int scroll_type,
short position, short position,
HWND scrollbar) { HWND scrollbar) {
message_handler_->OnVScroll(scroll_type, position, scrollbar); SetMsgHandled(FALSE);
} }
void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) {
...@@ -2184,30 +2290,6 @@ bool NativeWidgetWin::IsUsingCustomFrame() const { ...@@ -2184,30 +2290,6 @@ bool NativeWidgetWin::IsUsingCustomFrame() const {
return GetWidget()->ShouldUseNativeFrame(); return GetWidget()->ShouldUseNativeFrame();
} }
bool NativeWidgetWin::CanResize() const {
return GetWidget()->widget_delegate()->CanResize();
}
bool NativeWidgetWin::CanMaximize() const {
return GetWidget()->widget_delegate()->CanMaximize();
}
bool NativeWidgetWin::CanActivate() const {
return delegate_->CanActivate();
}
int NativeWidgetWin::GetNonClientComponent(const gfx::Point& point) const {
return delegate_->GetNonClientComponent(point);
}
void NativeWidgetWin::GetWindowMask(const gfx::Size& size, gfx::Path* path) {
GetWidget()->non_client_view()->GetWindowMask(size, path);
}
InputMethod* NativeWidgetWin::GetInputMethod() {
return GetWidget()->GetInputMethodDirect();
}
void NativeWidgetWin::HandleAppDeactivated() { void NativeWidgetWin::HandleAppDeactivated() {
// Another application was activated, we should reset any state that // Another application was activated, we should reset any state that
// disables inactive rendering now. // disables inactive rendering now.
...@@ -2263,18 +2345,6 @@ void NativeWidgetWin::HandleEndWMSizeMove() { ...@@ -2263,18 +2345,6 @@ void NativeWidgetWin::HandleEndWMSizeMove() {
delegate_->OnNativeWidgetEndUserBoundsChange(); delegate_->OnNativeWidgetEndUserBoundsChange();
} }
void NativeWidgetWin::HandleMove() {
delegate_->OnNativeWidgetMove();
}
void NativeWidgetWin::HandleNativeFocus(HWND last_focused_window) {
delegate_->OnNativeFocus(last_focused_window);
}
void NativeWidgetWin::HandleNativeBlur(HWND focused_window) {
delegate_->OnNativeBlur(focused_window);
}
NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() { NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() {
return this; return this;
} }
...@@ -2489,6 +2559,49 @@ void NativeWidgetWin::UpdateDWMFrame() { ...@@ -2489,6 +2559,49 @@ void NativeWidgetWin::UpdateDWMFrame() {
DwmExtendFrameIntoClientArea(GetNativeView(), &m); DwmExtendFrameIntoClientArea(GetNativeView(), &m);
} }
void NativeWidgetWin::ResetWindowRegion(bool force) {
// A native frame uses the native window region, and we don't want to mess
// with it.
if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) {
if (force)
SetWindowRgn(NULL, TRUE);
return;
}
// Changing the window region is going to force a paint. Only change the
// window region if the region really differs.
HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
int current_rgn_result = GetWindowRgn(GetNativeView(), current_rgn);
CRect window_rect;
GetWindowRect(&window_rect);
HRGN new_region;
if (IsMaximized()) {
HMONITOR monitor =
MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof mi;
GetMonitorInfo(monitor, &mi);
CRect work_rect = mi.rcWork;
work_rect.OffsetRect(-window_rect.left, -window_rect.top);
new_region = CreateRectRgnIndirect(&work_rect);
} else {
gfx::Path window_mask;
GetWidget()->non_client_view()->GetWindowMask(
gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask);
new_region = window_mask.CreateNativeRegion();
}
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
// SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
SetWindowRgn(new_region, TRUE);
} else {
DeleteObject(new_region);
}
DeleteObject(current_rgn);
}
LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message, LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param) { LPARAM l_param) {
......
...@@ -493,12 +493,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, ...@@ -493,12 +493,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
// Overridden from HWNDMessageHandlerDelegate: // Overridden from HWNDMessageHandlerDelegate:
virtual bool IsWidgetWindow() const OVERRIDE; virtual bool IsWidgetWindow() const OVERRIDE;
virtual bool IsUsingCustomFrame() const OVERRIDE; virtual bool IsUsingCustomFrame() const OVERRIDE;
virtual bool CanResize() const OVERRIDE;
virtual bool CanMaximize() const OVERRIDE;
virtual bool CanActivate() const OVERRIDE;
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
virtual void GetWindowMask(const gfx::Size& size, gfx::Path* path) OVERRIDE;
virtual InputMethod* GetInputMethod() OVERRIDE;
virtual void HandleAppDeactivated() OVERRIDE; virtual void HandleAppDeactivated() OVERRIDE;
virtual bool HandleAppCommand(short command) OVERRIDE; virtual bool HandleAppCommand(short command) OVERRIDE;
virtual void HandleCaptureLost() OVERRIDE; virtual void HandleCaptureLost() OVERRIDE;
...@@ -509,9 +503,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, ...@@ -509,9 +503,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual void HandleGlassModeChange() OVERRIDE; virtual void HandleGlassModeChange() OVERRIDE;
virtual void HandleBeginWMSizeMove() OVERRIDE; virtual void HandleBeginWMSizeMove() OVERRIDE;
virtual void HandleEndWMSizeMove() OVERRIDE; virtual void HandleEndWMSizeMove() OVERRIDE;
virtual void HandleMove() OVERRIDE;
virtual void HandleNativeFocus(HWND last_focused_window) OVERRIDE;
virtual void HandleNativeBlur(HWND focused_window) OVERRIDE;
virtual NativeWidgetWin* AsNativeWidgetWin() OVERRIDE; virtual NativeWidgetWin* AsNativeWidgetWin() OVERRIDE;
// Called after the WM_ACTIVATE message has been processed by the default // Called after the WM_ACTIVATE message has been processed by the default
...@@ -541,6 +532,11 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, ...@@ -541,6 +532,11 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
// or subsequently. // or subsequently.
void ClientAreaSizeChanged(); void ClientAreaSizeChanged();
// Resets the window region for the current widget bounds if necessary.
// If |force| is true, the window region is reset to NULL even for native
// frame windows.
void ResetWindowRegion(bool force);
// When removing the standard frame, tells the DWM how much glass we want on // When removing the standard frame, tells the DWM how much glass we want on
// the edges. Currently hardcoded to 10px on all sides. // the edges. Currently hardcoded to 10px on all sides.
void UpdateDWMFrame(); void UpdateDWMFrame();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment