Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1258)

Unified Diff: ui/views/widget/native_widget_win.cc

Issue 10836266: Begin to move some message handling from NWW onto a framework-agnostic HWND Message handler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/widget/native_widget_win.cc
===================================================================
--- ui/views/widget/native_widget_win.cc (revision 151828)
+++ ui/views/widget/native_widget_win.cc (working copy)
@@ -45,6 +45,7 @@
#include "ui/views/widget/aero_tooltip_manager.h"
#include "ui/views/widget/child_window_message_processor.h"
#include "ui/views/widget/drop_target_win.h"
+#include "ui/views/widget/hwnd_message_handler.h"
#include "ui/views/widget/monitor_win.h"
#include "ui/views/widget/native_widget_delegate.h"
#include "ui/views/widget/root_view.h"
@@ -429,7 +430,9 @@
is_right_mouse_pressed_on_caption_(false),
restored_enabled_(false),
destroyed_(NULL),
- has_non_client_view_(false) {
+ has_non_client_view_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ message_handler_(new HWNDMessageHandler(this))) {
}
NativeWidgetWin::~NativeWidgetWin() {
@@ -1257,58 +1260,36 @@
// Message handlers ------------------------------------------------------------
void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) {
- SetMsgHandled(FALSE);
+ message_handler_->OnActivate(action, minimized, window);
}
void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) {
- if (GetWidget()->non_client_view() && !active &&
- thread_id != GetCurrentThreadId()) {
- // Another application was activated, we should reset any state that
- // disables inactive rendering now.
- delegate_->EnableInactiveRendering();
- // Also update the native frame if it is rendering the non-client area.
- if (!remove_standard_frame_ && GetWidget()->ShouldUseNativeFrame())
- DefWindowProcWithRedrawLock(WM_NCACTIVATE, FALSE, 0);
- }
+ message_handler_->OnActivateApp(active, thread_id);
}
LRESULT NativeWidgetWin::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...
- BOOL is_handled = (GetWidget()->widget_delegate() &&
- GetWidget()->widget_delegate()->ExecuteWindowsCommand(app_command)) ?
- TRUE : FALSE;
- SetMsgHandled(is_handled);
- // Make sure to return TRUE if the event was handled or in some cases the
- // system will execute the default handler which can cause bugs like going
- // forward or back two pages instead of one.
- return is_handled;
+ return message_handler_->OnAppCommand(window, app_command, device, keystate);
}
void NativeWidgetWin::OnCancelMode() {
- SetMsgHandled(FALSE);
+ message_handler_->OnCancelMode();
}
void NativeWidgetWin::OnCaptureChanged(HWND hwnd) {
- delegate_->OnMouseCaptureLost();
+ message_handler_->OnCaptureChanged(hwnd);
}
void NativeWidgetWin::OnClose() {
- GetWidget()->Close();
+ message_handler_->OnClose();
}
void NativeWidgetWin::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 ||
- GetWidget()->widget_delegate()->ExecuteWindowsCommand(command_id)) {
- SetMsgHandled(FALSE);
- }
+ message_handler_->OnCommand(notification_code, command_id, window);
}
LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
@@ -1357,7 +1338,7 @@
// We should attach IMEs only when we need to input CJK strings.
ImmAssociateContextEx(hwnd(), NULL, 0);
- if (remove_standard_frame_) {
+ if (message_handler_->remove_standard_frame()) {
SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) & ~WS_CAPTION);
SendFrameChanged(GetNativeView());
}
@@ -1379,56 +1360,38 @@
}
void NativeWidgetWin::OnDestroy() {
- delegate_->OnNativeWidgetDestroying();
- if (drop_target_.get()) {
- RevokeDragDrop(hwnd());
- drop_target_ = NULL;
- }
+ message_handler_->OnDestroy();
}
void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) {
- GetWidget()->widget_delegate()->OnDisplayChanged();
+ message_handler_->OnDisplayChange(bits_per_pixel, screen_size);
}
LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT msg,
WPARAM w_param,
LPARAM l_param) {
- if (!GetWidget()->non_client_view()) {
- SetMsgHandled(FALSE);
- return 0;
- }
-
- // For some reason, we need to hide the window while we're changing the frame
- // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED.
- // If we don't, the client area will be filled with black. I'm suspecting
- // something skia-ey.
- // Frame type toggling caused by the user (e.g. switching theme) doesn't seem
- // to have this requirement.
- FrameTypeChanged();
+ message_handler_->OnDwmCompositionChanged(msg, w_param, l_param);
return 0;
}
void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) {
- SetMsgHandled(FALSE);
+ message_handler_->OnEndSession(ending, logoff);
}
void NativeWidgetWin::OnEnterSizeMove() {
- delegate_->OnNativeWidgetBeginUserBoundsChange();
- SetMsgHandled(FALSE);
+ message_handler_->OnEnterSizeMove();
}
LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) {
- // This is needed for magical win32 flicker ju-ju.
- return 1;
+ return message_handler_->OnEraseBkgnd(dc);
}
void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) {
- SetMsgHandled(FALSE);
+ message_handler_->OnExitMenuLoop(is_track_popup_menu);
}
void NativeWidgetWin::OnExitSizeMove() {
- delegate_->OnNativeWidgetEndUserBoundsChange();
- SetMsgHandled(FALSE);
+ message_handler_->OnExitSizeMove();
}
LRESULT NativeWidgetWin::OnGetObject(UINT uMsg,
@@ -1732,7 +1695,7 @@
// requests it, we want a custom width of 0.
gfx::Insets insets = GetClientAreaInsets();
if (insets.empty() && !IsFullscreen() &&
- !(mode && remove_standard_frame_)) {
+ !(mode && message_handler_->remove_standard_frame())) {
SetMsgHandled(FALSE);
return 0;
}
@@ -1817,7 +1780,8 @@
// 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_ && GetWidget()->ShouldUseNativeFrame()) {
+ if (!message_handler_->remove_standard_frame() &&
+ GetWidget()->ShouldUseNativeFrame()) {
LRESULT result;
if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
MAKELPARAM(point.x, point.y), &result)) {
@@ -2211,9 +2175,11 @@
void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
if (DidClientAreaSizeChange(window_pos))
ClientAreaSizeChanged();
- if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED &&
- IsAeroGlassEnabled())
+ if (message_handler_->remove_standard_frame() &&
+ window_pos->flags & SWP_FRAMECHANGED &&
+ IsAeroGlassEnabled()) {
UpdateDWMFrame();
+ }
if (window_pos->flags & SWP_SHOWWINDOW)
delegate_->OnNativeWidgetVisibilityChanged(true);
else if (window_pos->flags & SWP_HIDEWINDOW)
@@ -2241,7 +2207,8 @@
// Returning an empty Insets object causes the default handling in
// NativeWidgetWin::OnNCCalcSize() to be invoked.
if (!has_non_client_view_ ||
- (GetWidget()->ShouldUseNativeFrame() && !remove_standard_frame_))
+ (GetWidget()->ShouldUseNativeFrame() &&
+ !message_handler_->remove_standard_frame()))
return gfx::Insets();
if (IsMaximized()) {
@@ -2254,7 +2221,7 @@
// The hack below doesn't seem to be necessary when the standard frame is
// removed.
- if (remove_standard_frame_)
+ if (message_handler_->remove_standard_frame())
return gfx::Insets();
// This is weird, but highly essential. If we don't offset the bottom edge
// of the client rect, the window client area and window area will match,
@@ -2313,6 +2280,76 @@
}
////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetWin, HWNDMessageHandlerDelegate implementation:
+
+bool NativeWidgetWin::IsWidgetWindow() const {
+ return !!GetWidget()->non_client_view();
+}
+
+bool NativeWidgetWin::IsUsingCustomFrame() const {
+ return GetWidget()->ShouldUseNativeFrame();
+}
+
+void NativeWidgetWin::HandleAppDeactivated() {
+ // Another application was activated, we should reset any state that
+ // disables inactive rendering now.
+ delegate_->EnableInactiveRendering();
+}
+
+bool NativeWidgetWin::HandleAppCommand(short command) {
+ // We treat APPCOMMAND ids as an extension of our command namespace, and just
+ // let the delegate figure out what to do...
+ return GetWidget()->widget_delegate() &&
+ GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
+}
+
+void NativeWidgetWin::HandleCaptureLost() {
+ delegate_->OnMouseCaptureLost();
+}
+
+void NativeWidgetWin::HandleClose() {
+ GetWidget()->Close();
+}
+
+bool NativeWidgetWin::HandleCommand(int command) {
+ return GetWidget()->widget_delegate()->ExecuteWindowsCommand(command);
+}
+
+void NativeWidgetWin::HandleDestroy() {
+ delegate_->OnNativeWidgetDestroying();
+ if (drop_target_.get()) {
+ RevokeDragDrop(hwnd());
+ drop_target_ = NULL;
+ }
+}
+
+void NativeWidgetWin::HandleDisplayChange() {
+ GetWidget()->widget_delegate()->OnDisplayChanged();
+}
+
+void NativeWidgetWin::HandleGlassModeChange() {
+ // For some reason, we need to hide the window while we're changing the frame
+ // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED.
+ // If we don't, the client area will be filled with black. I'm suspecting
+ // something skia-ey.
+ // Frame type toggling caused by the user (e.g. switching theme) doesn't seem
+ // to have this requirement.
+ FrameTypeChanged();
+}
+
+void NativeWidgetWin::HandleBeginWMSizeMove() {
+ delegate_->OnNativeWidgetBeginUserBoundsChange();
+}
+
+void NativeWidgetWin::HandleEndWMSizeMove() {
+ delegate_->OnNativeWidgetEndUserBoundsChange();
+}
+
+NativeWidgetWin* NativeWidgetWin::AsNativeWidgetWin() {
+ return this;
+}
+
+////////////////////////////////////////////////////////////////////////////////
// NativeWidgetWin, private:
// static
@@ -2441,7 +2478,7 @@
set_window_ex_style(window_ex_style() | ex_style);
has_non_client_view_ = Widget::RequiresNonClientView(params.type);
- remove_standard_frame_ = params.remove_standard_frame;
+ message_handler_->set_remove_standard_frame(params.remove_standard_frame);
}
void NativeWidgetWin::RedrawInvalidRect() {
« no previous file with comments | « ui/views/widget/native_widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698