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

Revert 152388 - Revert 152374 - Move more message handlers from...

Revert 152388 - Revert 152374 - Move more message handlers from NativeWidgetWin to HWNDMessageHandler.

Buildbots (not trybots) were giving grief on past iteration of this CL:
http://codereview.chromium.org/10832345/
... so I am splitting it into smaller pieces to help identify what piece was the cause.

http://crbug.com/142962
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10831394

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152390 0039d316-1c4b-4281-b951-d872f2087c98
parent 4002415c
......@@ -4,7 +4,10 @@
#include "ui/views/widget/hwnd_message_handler.h"
#include <dwmapi.h>
#include "base/system_monitor/system_monitor.h"
#include "ui/gfx/path.h"
#include "ui/base/native_theme/native_theme_win.h"
#include "ui/views/ime/input_method_win.h"
#include "ui/views/widget/hwnd_message_handler_delegate.h"
......@@ -132,6 +135,24 @@ LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
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();
......@@ -141,6 +162,28 @@ void HWNDMessageHandler::OnInputLangChange(DWORD character_set,
}
}
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);
}
void HWNDMessageHandler::OnMove(const CPoint& point) {
delegate_->HandleMove();
SetMsgHandled(FALSE);
......@@ -150,6 +193,36 @@ 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) {
......@@ -176,6 +249,37 @@ LRESULT HWNDMessageHandler::OnPowerBroadcast(DWORD power_event, DWORD data) {
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
......
......@@ -49,12 +49,22 @@ class VIEWS_EXPORT HWNDMessageHandler {
void OnExitMenuLoop(BOOL is_track_popup_menu);
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);
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);
......
......@@ -7,6 +7,12 @@
#include "ui/views/views_export.h"
namespace gfx {
class Path;
class Point;
class Size;
}
namespace views {
class InputMethod;
......@@ -22,6 +28,13 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
// to avoid confusion.
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
......@@ -61,6 +74,12 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
// 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.
// TODO(beng): should be removed once HWNDMessageHandler is the WindowImpl.
virtual NativeWidgetWin* AsNativeWidgetWin() = 0;
......
......@@ -1461,28 +1461,13 @@ LRESULT NativeWidgetWin::OnImeMessages(UINT message,
}
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);
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);
message_handler_->OnInitMenu(menu);
}
void NativeWidgetWin::OnInitMenuPopup(HMENU menu,
UINT position,
BOOL is_system_menu) {
SetMsgHandled(FALSE);
message_handler_->OnInitMenu(menu);
}
void NativeWidgetWin::OnInputLangChange(DWORD character_set,
......@@ -1493,22 +1478,11 @@ void NativeWidgetWin::OnInputLangChange(DWORD character_set,
LRESULT NativeWidgetWin::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 = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->DispatchKeyEvent(key);
else
DispatchKeyEventPostIME(key);
return 0;
return message_handler_->OnKeyEvent(message, w_param, l_param);
}
void NativeWidgetWin::OnKillFocus(HWND focused_window) {
delegate_->OnNativeBlur(focused_window);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->OnBlur();
SetMsgHandled(FALSE);
message_handler_->OnKillFocus(focused_window);
}
LRESULT NativeWidgetWin::OnMouseActivate(UINT message,
......@@ -1755,34 +1729,7 @@ LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
}
LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& 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;
return message_handler_->OnNCHitTest(point);
}
void NativeWidgetWin::OnNCPaint(HRGN rgn) {
......@@ -1927,32 +1874,19 @@ LRESULT NativeWidgetWin::OnReflectedMessage(UINT msg,
LRESULT NativeWidgetWin::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;
return message_handler_->OnSetCursor(message, w_param, l_param);
}
void NativeWidgetWin::OnSetFocus(HWND old_focused_window) {
delegate_->OnNativeFocus(old_focused_window);
InputMethod* input_method = GetWidget()->GetInputMethodDirect();
if (input_method)
input_method->OnFocus();
SetMsgHandled(FALSE);
message_handler_->OnSetFocus(old_focused_window);
}
LRESULT NativeWidgetWin::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));
return message_handler_->OnSetIcon(size_type, new_icon);
}
LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) {
// Use a ScopedRedrawLock to avoid weird non-client painting.
return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL,
reinterpret_cast<LPARAM>(text));
return message_handler_->OnSetText(text);
}
void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
......@@ -2258,6 +2192,26 @@ bool NativeWidgetWin::IsUsingCustomFrame() const {
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();
}
......@@ -2321,6 +2275,14 @@ 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() {
return this;
}
......
......@@ -494,6 +494,11 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
// Overridden from HWNDMessageHandlerDelegate:
virtual bool IsWidgetWindow() 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 bool HandleAppCommand(short command) OVERRIDE;
......@@ -506,6 +511,8 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual void HandleBeginWMSizeMove() 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;
// Called after the WM_ACTIVATE message has been processed by the default
......
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