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

Unified Diff: ui/views/win/hwnd_message_handler.cc

Issue 10867096: Make HWNDMessageHandler subclass WindowImpl. (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
Index: ui/views/win/hwnd_message_handler.cc
===================================================================
--- ui/views/win/hwnd_message_handler.cc (revision 153552)
+++ ui/views/win/hwnd_message_handler.cc (working copy)
@@ -28,7 +28,6 @@
#include "ui/views/views_delegate.h"
#include "ui/views/widget/child_window_message_processor.h"
#include "ui/views/widget/monitor_win.h"
-#include "ui/views/widget/native_widget_win.h"
#include "ui/views/widget/widget_hwnd_utils.h"
#include "ui/views/win/fullscreen_handler.h"
#include "ui/views/win/hwnd_message_handler_delegate.h"
@@ -361,8 +360,8 @@
HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate)
: delegate_(delegate),
- ALLOW_THIS_IN_INITIALIZER_LIST(fullscreen_handler_(new FullscreenHandler(
- delegate->AsNativeWidgetWin()->GetWidget()))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ fullscreen_handler_(new FullscreenHandler)),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
remove_standard_frame_(false),
restore_focus_when_enabled_(false),
@@ -386,9 +385,18 @@
*destroyed_ = true;
}
-void HWNDMessageHandler::Init(const gfx::Rect& bounds) {
+void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
&last_work_area_);
+ // Create the window.
+ WindowImpl::Init(parent, bounds);
+ fullscreen_handler_->set_hwnd(hwnd());
+
+ // We need to add ourselves as a message loop observer so that we can repaint
+ // aggressively if the contents of our window become invalid. Unfortunately
+ // WM_PAINT messages are starved and we get flickery redrawing when resizing
+ // if we do not do this.
+ MessageLoopForUI::current()->AddObserver(this);
}
void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) {
@@ -921,8 +929,7 @@
}
LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
- use_layered_buffer_ = !!(delegate_->AsNativeWidgetWin()->
- window_ex_style() & WS_EX_LAYERED);
+ use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED);
// Attempt to detect screen readers by sending an event with our custom id.
NotifyWinEvent(EVENT_SYSTEM_ALERT, hwnd(), kCustomObjectID, CHILDID_SELF);
@@ -982,6 +989,7 @@
}
void HWNDMessageHandler::OnEndSession(BOOL ending, UINT logoff) {
+ delegate_->HandleEndSession();
SetMsgHandled(FALSE);
}
@@ -1011,7 +1019,7 @@
// Add the native frame border size to the minimum and maximum size if the
// view reports its size as the client size.
- if (delegate_->AsNativeWidgetWin()->WidgetSizeIsClientSize()) {
+ if (delegate_->WidgetSizeIsClientSize()) {
CRect client_rect, window_rect;
GetClientRect(hwnd(), &client_rect);
GetWindowRect(hwnd(), &window_rect);
@@ -1099,7 +1107,10 @@
!is_minimized);
}
-void HWNDMessageHandler::OnInitMenuPopup() {
+void HWNDMessageHandler::OnInitMenuPopup(HMENU menu,
+ UINT position,
+ BOOL is_system_menu) {
+ delegate_->HandleInitMenuPopup();
SetMsgHandled(FALSE);
}
@@ -1137,6 +1148,7 @@
LRESULT HWNDMessageHandler::OnMouseActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
+ delegate_->HandleMouseActivate(LOWORD(l_param));
// TODO(beng): resolve this with the GetWindowLong() check on the subsequent
// line.
if (delegate_->IsWidgetWindow())
@@ -1767,12 +1779,16 @@
}
void HWNDMessageHandler::OnWindowPosChanged(WINDOWPOS* window_pos) {
+
if (DidClientAreaSizeChange(window_pos))
ClientAreaSizeChanged();
- if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED &&
- ui::win::IsAeroGlassEnabled()) {
- MARGINS m = {10, 10, 10, 10};
- DwmExtendFrameIntoClientArea(hwnd(), &m);
+ if (window_pos->flags & SWP_FRAMECHANGED) {
+ delegate_->HandleFrameChanged();
+ if (remove_standard_frame_ && ui::win::IsAeroGlassEnabled()) {
+ delegate_->HandleFrameChanged();
+ MARGINS m = {10, 10, 10, 10};
+ DwmExtendFrameIntoClientArea(hwnd(), &m);
+ }
}
if (window_pos->flags & SWP_SHOWWINDOW)
delegate_->HandleVisibilityChanged(true);
@@ -1823,14 +1839,6 @@
DeleteObject(current_rgn);
}
-HWND HWNDMessageHandler::hwnd() {
- return delegate_->AsNativeWidgetWin()->hwnd();
-}
-
-HWND HWNDMessageHandler::hwnd() const {
- return delegate_->AsNativeWidgetWin()->hwnd();
-}
-
////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, InputMethodDelegate implementation:
@@ -1852,6 +1860,9 @@
HWND window = hwnd();
LRESULT result = 0;
+ if (delegate_->HandleMSG(message, w_param, l_param, &result))
+ return result;
+
// First allow messages sent by child controls to be processed directly by
// their associated views. If such a view is present, it will handle the
// message *instead of* this NativeWidgetWin.
@@ -1859,12 +1870,12 @@
return result;
// Otherwise we handle everything else.
- if (!delegate_->AsNativeWidgetWin()->ProcessWindowMessage(
- window, message, w_param, l_param, result)) {
+ if (!ProcessWindowMessage(window, message, w_param, l_param, result))
result = DefWindowProc(window, message, w_param, l_param);
+ if (message == WM_NCDESTROY) {
+ MessageLoopForUI::current()->RemoveObserver(this);
+ delegate_->HandleDestroyed();
}
- if (message == WM_NCDESTROY)
- delegate_->HandleDestroyed();
// Only top level widget should store/restore focus.
if (message == WM_ACTIVATE && delegate_->CanSaveFocus())
@@ -1879,7 +1890,18 @@
return result;
}
+////////////////////////////////////////////////////////////////////////////////
+// HWNDMessageHandler, MessageLoop::Observer implementation:
+base::EventStatus HWNDMessageHandler::WillProcessEvent(
+ const base::NativeEvent& event) {
+ return base::EVENT_CONTINUE;
+}
+
+void HWNDMessageHandler::DidProcessEvent(const base::NativeEvent& event) {
+ RedrawInvalidRect();
+}
+
////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, private:
@@ -1960,7 +1982,7 @@
void HWNDMessageHandler::ClientAreaSizeChanged() {
RECT r = {0, 0, 0, 0};
- if (delegate_->AsNativeWidgetWin()->WidgetSizeIsClientSize()) {
+ if (delegate_->WidgetSizeIsClientSize()) {
// TODO(beng): investigate whether this could be done
// from other branch of if-else.
if (!IsMinimized())
@@ -2095,8 +2117,4 @@
skia::EndPlatformPaint(layered_window_contents_->sk_canvas());
}
-void HWNDMessageHandler::SetMsgHandled(BOOL handled) {
- delegate_->AsNativeWidgetWin()->SetMsgHandled(handled);
-}
-
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698