Commit 5b7209f6 authored by ben@chromium.org's avatar ben@chromium.org

Revert 151762.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151771 0039d316-1c4b-4281-b951-d872f2087c98
parent 6bf3373d
......@@ -321,9 +321,6 @@
'widget/drop_helper.h',
'widget/drop_target_win.cc',
'widget/drop_target_win.h',
'widget/hwnd_message_handler.cc',
'widget/hwnd_message_handler.h',
'widget/hwnd_message_handler_delegate.h',
'widget/root_view.cc',
'widget/root_view.h',
'widget/tooltip_manager_aura.cc',
......@@ -449,9 +446,6 @@
}],
['OS!="win"', {
'sources!': [
'widget/hwnd_message_handler.cc',
'widget/hwnd_message_handler.h',
'widget/hwnd_message_handler_delegate.h',
'widget/widget_hwnd_utils.cc',
'widget/widget_hwnd_utils.h',
],
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/widget/hwnd_message_handler.h"
#include "ui/views/widget/hwnd_message_handler_delegate.h"
#include "ui/views/widget/native_widget_win.h"
namespace views {
////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, public:
HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate)
: delegate_(delegate),
remove_standard_frame_(false) {
}
HWNDMessageHandler::~HWNDMessageHandler() {
}
void HWNDMessageHandler::OnActivate(UINT action, BOOL minimized, HWND window) {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) {
if (delegate_->IsWidgetWindow() && !active &&
thread_id != GetCurrentThreadId()) {
delegate_->HandleAppDeactivated();
// Also update the native frame if it is rendering the non-client area.
if (!remove_standard_frame_ &&
!delegate_->IsUsingCustomFrame() &&
delegate_->AsNativeWidgetWin()) {
delegate_->AsNativeWidgetWin()->DefWindowProcWithRedrawLock(
WM_NCACTIVATE, FALSE, 0);
}
}
}
BOOL HWNDMessageHandler::OnAppCommand(HWND window,
short command,
WORD device,
int keystate) {
BOOL handled = !!delegate_->HandleAppCommand(command);
SetMsgHandled(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 handled;
}
void HWNDMessageHandler::OnCancelMode() {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnCaptureChanged(HWND window) {
delegate_->HandleCaptureLost();
}
void HWNDMessageHandler::OnClose() {
delegate_->HandleClose();
}
void HWNDMessageHandler::OnCommand(UINT notification_code,
int command,
HWND window) {
// If the notification code is > 1 it means it is control specific and we
// should ignore it.
if (notification_code > 1 || delegate_->HandleAppCommand(command))
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnDestroy() {
delegate_->HandleDestroy();
}
void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel,
const CSize& screen_size) {
delegate_->HandleDisplayChange();
}
void HWNDMessageHandler::OnDwmCompositionChanged(UINT msg,
WPARAM w_param,
LPARAM l_param) {
if (!delegate_->IsWidgetWindow()) {
SetMsgHandled(FALSE);
return;
}
delegate_->HandleGlassModeChange();
}
void HWNDMessageHandler::OnEndSession(BOOL ending, UINT logoff) {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnEnterSizeMove() {
delegate_->HandleBeginWMSizeMove();
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) {
// Needed to prevent resize flicker.
return 1;
}
void HWNDMessageHandler::OnExitMenuLoop(BOOL is_track_popup_menu) {
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnExitSizeMove() {
delegate_->HandleEndWMSizeMove();
SetMsgHandled(FALSE);
}
////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, private:
void HWNDMessageHandler::SetMsgHandled(BOOL handled) {
delegate_->AsNativeWidgetWin()->SetMsgHandled(handled);
}
} // namespace views
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_H_
#define UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_H_
#include <atlbase.h>
#include <atlapp.h>
#include <atlmisc.h>
#include <windows.h>
#include "base/basictypes.h"
#include "ui/views/views_export.h"
namespace views {
class HWNDMessageHandlerDelegate;
// An object that handles messages for a HWND that implements the views
// "Custom Frame" look. The purpose of this class is to isolate the windows-
// specific message handling from the code that wraps it. It is intended to be
// used by both a views::NativeWidget and an aura::RootWindowHost
// implementation.
// TODO(beng): This object should eventually *become* the WindowImpl.
class VIEWS_EXPORT HWNDMessageHandler {
public:
explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate);
~HWNDMessageHandler();
// Message Handlers.
void OnActivate(UINT action, BOOL minimized, HWND window);
// TODO(beng): Once this object becomes the WindowImpl, these methods can
// be made private.
void OnActivateApp(BOOL active, DWORD thread_id);
// TODO(beng): return BOOL is temporary until this object becomes a
// WindowImpl.
BOOL OnAppCommand(HWND window, short command, WORD device, int keystate);
void OnCancelMode();
void OnCaptureChanged(HWND window);
void OnClose();
void OnCommand(UINT notification_code, int command, HWND window);
void OnDestroy();
void OnDisplayChange(UINT bits_per_pixel, const CSize& screen_size);
void OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param);
void OnEndSession(BOOL ending, UINT logoff);
void OnEnterSizeMove();
LRESULT OnEraseBkgnd(HDC dc);
void OnExitMenuLoop(BOOL is_track_popup_menu);
void OnExitSizeMove();
// TODO(beng): Can be removed once this object becomes the WindowImpl.
bool remove_standard_frame() const { return remove_standard_frame_; }
void set_remove_standard_frame(bool remove_standard_frame) {
remove_standard_frame_ = remove_standard_frame;
}
private:
// TODO(beng): Remove once this class becomes the WindowImpl.
void SetMsgHandled(BOOL handled);
HWNDMessageHandlerDelegate* delegate_;
bool remove_standard_frame_;
DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
};
} // namespace views
#endif // UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_DELEGATE_H_
#define UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_DELEGATE_H_
#include "ui/views/views_export.h"
namespace views {
class NativeWidgetWin;
// Implemented by the object that uses the HWNDMessageHandler to handle
// notifications from the underlying HWND and service requests for data.
class VIEWS_EXPORT HWNDMessageHandlerDelegate {
public:
virtual bool IsWidgetWindow() const = 0;
// TODO(beng): resolve this more satisfactorily vis-a-vis ShouldUseNativeFrame
// to avoid confusion.
virtual bool IsUsingCustomFrame() const = 0;
// TODO(beng): Investigate migrating these methods to On* prefixes once
// HWNDMessageHandler is the WindowImpl.
// Called when another app was activated.
virtual void HandleAppDeactivated() = 0;
// Called when a well known "app command" from the system was performed.
// Returns true if the command was handled.
virtual bool HandleAppCommand(short command) = 0;
// Called when the window has lost mouse capture.
virtual void HandleCaptureLost() = 0;
// Called when the user tried to close the window.
virtual void HandleClose() = 0;
// Called when a command defined by the application was performed. Returns
// true if the command was handled.
virtual bool HandleCommand(int command) = 0;
// Called when the HWND is destroyed.
virtual void HandleDestroy() = 0;
// Called when display settings are adjusted on the system.
virtual void HandleDisplayChange() = 0;
// Called when the system changes from glass to non-glass or vice versa.
virtual void HandleGlassModeChange() = 0;
// Called when the user begins or ends a size/move operation using the window
// manager.
virtual void HandleBeginWMSizeMove() = 0;
virtual void HandleEndWMSizeMove() = 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;
protected:
virtual ~HWNDMessageHandlerDelegate() {}
};
} // namespace views
#endif // UI_VIEWS_WIDGET_HWND_MESSAGE_HANDLER_DELEGATE_H_
......@@ -45,7 +45,6 @@
#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"
......@@ -430,9 +429,7 @@ NativeWidgetWin::NativeWidgetWin(internal::NativeWidgetDelegate* delegate)
is_right_mouse_pressed_on_caption_(false),
restored_enabled_(false),
destroyed_(NULL),
has_non_client_view_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(
message_handler_(new HWNDMessageHandler(this))) {
has_non_client_view_(false) {
}
NativeWidgetWin::~NativeWidgetWin() {
......@@ -1260,36 +1257,58 @@ LRESULT NativeWidgetWin::OnWndProc(UINT message,
// Message handlers ------------------------------------------------------------
void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) {
message_handler_->OnActivate(action, minimized, window);
SetMsgHandled(FALSE);
}
void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) {
message_handler_->OnActivateApp(active, 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);
}
}
LRESULT NativeWidgetWin::OnAppCommand(HWND window,
short app_command,
WORD device,
int keystate) {
return message_handler_->OnAppCommand(window, app_command, device, 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;
}
void NativeWidgetWin::OnCancelMode() {
message_handler_->OnCancelMode();
SetMsgHandled(FALSE);
}
void NativeWidgetWin::OnCaptureChanged(HWND hwnd) {
message_handler_->OnCaptureChanged(hwnd);
delegate_->OnMouseCaptureLost();
}
void NativeWidgetWin::OnClose() {
message_handler_->OnClose();
GetWidget()->Close();
}
void NativeWidgetWin::OnCommand(UINT notification_code,
int command_id,
HWND window) {
message_handler_->OnCommand(notification_code, command_id, 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);
}
}
LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
......@@ -1338,7 +1357,7 @@ LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
// We should attach IMEs only when we need to input CJK strings.
ImmAssociateContextEx(hwnd(), NULL, 0);
if (message_handler_->remove_standard_frame()) {
if (remove_standard_frame_) {
SetWindowLong(GWL_STYLE, GetWindowLong(GWL_STYLE) & ~WS_CAPTION);
SendFrameChanged(GetNativeView());
}
......@@ -1360,38 +1379,56 @@ LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
}
void NativeWidgetWin::OnDestroy() {
message_handler_->OnDestroy();
delegate_->OnNativeWidgetDestroying();
if (drop_target_.get()) {
RevokeDragDrop(hwnd());
drop_target_ = NULL;
}
}
void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) {
message_handler_->OnDisplayChange(bits_per_pixel, screen_size);
GetWidget()->widget_delegate()->OnDisplayChanged();
}
LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT msg,
WPARAM w_param,
LPARAM l_param) {
message_handler_->OnDwmCompositionChanged(msg, w_param, 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();
return 0;
}
void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) {
message_handler_->OnEndSession(ending, logoff);
SetMsgHandled(FALSE);
}
void NativeWidgetWin::OnEnterSizeMove() {
message_handler_->OnEnterSizeMove();
delegate_->OnNativeWidgetBeginUserBoundsChange();
SetMsgHandled(FALSE);
}
LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) {
return message_handler_->OnEraseBkgnd(dc);
// This is needed for magical win32 flicker ju-ju.
return 1;
}
void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) {
message_handler_->OnExitMenuLoop(is_track_popup_menu);
SetMsgHandled(FALSE);
}
void NativeWidgetWin::OnExitSizeMove() {
message_handler_->OnExitSizeMove();
delegate_->OnNativeWidgetEndUserBoundsChange();
SetMsgHandled(FALSE);
}
LRESULT NativeWidgetWin::OnGetObject(UINT uMsg,
......@@ -1695,7 +1732,7 @@ LRESULT NativeWidgetWin::OnNCCalcSize(BOOL mode, LPARAM l_param) {
// requests it, we want a custom width of 0.
gfx::Insets insets = GetClientAreaInsets();
if (insets.empty() && !IsFullscreen() &&
!(mode && message_handler_->remove_standard_frame())) {
!(mode && remove_standard_frame_)) {
SetMsgHandled(FALSE);
return 0;
}
......@@ -1780,8 +1817,7 @@ LRESULT NativeWidgetWin::OnNCHitTest(const CPoint& point) {
// 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()) {
if (!remove_standard_frame_ && GetWidget()->ShouldUseNativeFrame()) {
LRESULT result;
if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0,
MAKELPARAM(point.x, point.y), &result)) {
......@@ -2175,11 +2211,9 @@ void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) {
void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
if (DidClientAreaSizeChange(window_pos))
ClientAreaSizeChanged();
if (message_handler_->remove_standard_frame() &&
window_pos->flags & SWP_FRAMECHANGED &&
IsAeroGlassEnabled()) {
if (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)
......@@ -2207,8 +2241,7 @@ gfx::Insets NativeWidgetWin::GetClientAreaInsets() const {
// Returning an empty Insets object causes the default handling in
// NativeWidgetWin::OnNCCalcSize() to be invoked.
if (!has_non_client_view_ ||
(GetWidget()->ShouldUseNativeFrame() &&
!message_handler_->remove_standard_frame()))
(GetWidget()->ShouldUseNativeFrame() && !remove_standard_frame_))
return gfx::Insets();
if (IsMaximized()) {
......@@ -2221,7 +2254,7 @@ gfx::Insets NativeWidgetWin::GetClientAreaInsets() const {
// The hack below doesn't seem to be necessary when the standard frame is
// removed.
if (message_handler_->remove_standard_frame())
if (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,
......@@ -2279,76 +2312,6 @@ void NativeWidgetWin::ExecuteSystemMenuCommand(int command) {
SendMessage(GetNativeView(), WM_SYSCOMMAND, command, 0);
}
////////////////////////////////////////////////////////////////////////////////
// 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:
......@@ -2478,7 +2441,7 @@ void NativeWidgetWin::SetInitParams(const Widget::InitParams& params) {
set_window_ex_style(window_ex_style() | ex_style);
has_non_client_view_ = Widget::RequiresNonClientView(params.type);
message_handler_->set_remove_standard_frame(params.remove_standard_frame);
remove_standard_frame_ = params.remove_standard_frame;
}
void NativeWidgetWin::RedrawInvalidRect() {
......
......@@ -24,7 +24,6 @@
#include "ui/base/win/window_impl.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/layout/layout_manager.h"
#include "ui/views/widget/hwnd_message_handler_delegate.h"
#include "ui/views/widget/native_widget_private.h"
namespace ui {
......@@ -41,7 +40,6 @@ class Rect;
namespace views {
class DropTargetWin;
class HWNDMessageHandler;
class RootView;
class TooltipManagerWin;
......@@ -71,8 +69,7 @@ const int WM_NCUAHDRAWFRAME = 0xAF;
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
public MessageLoopForUI::Observer,
public internal::NativeWidgetPrivate,
public HWNDMessageHandlerDelegate {
public internal::NativeWidgetPrivate {
public:
explicit NativeWidgetWin(internal::NativeWidgetDelegate* delegate);
virtual ~NativeWidgetWin();
......@@ -486,25 +483,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
typedef ScopedVector<ui::ViewProp> ViewProps;
typedef std::set<DWORD> TouchIDs;
// TODO(beng): This friendship can be removed once all methods relating to
// this object being a WindowImpl are moved to HWNDMessageHandler.
friend HWNDMessageHandler;
// Overridden from HWNDMessageHandlerDelegate:
virtual bool IsWidgetWindow() const OVERRIDE;
virtual bool IsUsingCustomFrame() const OVERRIDE;
virtual void HandleAppDeactivated() OVERRIDE;
virtual bool HandleAppCommand(short command) OVERRIDE;
virtual void HandleCaptureLost() OVERRIDE;
virtual void HandleClose() OVERRIDE;
virtual bool HandleCommand(int command) OVERRIDE;
virtual void HandleDestroy() OVERRIDE;
virtual void HandleDisplayChange() OVERRIDE;
virtual void HandleGlassModeChange() OVERRIDE;
virtual void HandleBeginWMSizeMove() OVERRIDE;
virtual void HandleEndWMSizeMove() OVERRIDE;
virtual NativeWidgetWin* AsNativeWidgetWin() OVERRIDE;
// Called after the WM_ACTIVATE message has been processed by the default
// windows procedure.
static void PostProcessActivateMessage(NativeWidgetWin* widget,
......@@ -699,11 +677,11 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
// Init time, before the Widget has created the NonClientView.
bool has_non_client_view_;
bool remove_standard_frame_;
// The set of touch devices currently down.
TouchIDs touch_ids_;
scoped_ptr<HWNDMessageHandler> message_handler_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin);
};
......
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