This source file includes following definitions.
- got_mouse_up
- key_hook_
- Unhook
- MouseHook
- KeyHook
- EnumChildWindowsForRedraw
- GetMonitorAndRects
- EnableMenuItemByCommand
- SendDwmCompositionChanged
- ClipDCToChild
- IsTopLevelWindow
- AddScrollStylesToWindow
- force_
- ScopedRedrawLock
- CancelUnlockOperation
- touch_down_context_
- Init
- InitModalType
- Close
- CloseNow
- GetWindowBoundsInScreen
- GetClientAreaBoundsInScreen
- GetRestoredBounds
- GetClientAreaBounds
- GetWindowPlacement
- SetBounds
- SetSize
- CenterWindow
- SetRegion
- StackAbove
- StackAtTop
- Show
- ShowWindowWithState
- ShowMaximizedWithBounds
- Hide
- Maximize
- Minimize
- Restore
- Activate
- Deactivate
- SetAlwaysOnTop
- IsVisible
- IsActive
- IsMinimized
- IsMaximized
- IsAlwaysOnTop
- RunMoveLoop
- EndMoveLoop
- SendFrameChanged
- FlashFrame
- ClearNativeFocus
- SetCapture
- ReleaseCapture
- HasCapture
- SetVisibilityChangedAnimationsEnabled
- SetTitle
- SetCursor
- FrameTypeChanged
- SchedulePaintInRect
- SetOpacity
- SetWindowIcons
- DispatchKeyEventPostIME
- GetDefaultWindowIcon
- OnWndProc
- HandleMouseMessage
- HandleTouchMessage
- HandleKeyboardMessage
- HandleScrollMessage
- HandleNcHitTestMessage
- GetAppbarAutohideEdges
- OnAppbarAutohideEdgesChanged
- SetInitialFocus
- PostProcessActivateMessage
- RestoreEnabledIfNecessary
- ExecuteSystemMenuCommand
- TrackMouseEvents
- ClientAreaSizeChanged
- GetClientAreaInsets
- ResetWindowRegion
- UpdateDwmNcRenderingPolicy
- DefWindowProcWithRedrawLock
- LockUpdates
- UnlockUpdates
- RedrawLayeredWindowContents
- ForceRedrawWindow
- OnActivateApp
- OnAppCommand
- OnCancelMode
- OnCaptureChanged
- OnClose
- OnCommand
- OnCreate
- OnDestroy
- OnDisplayChange
- OnDwmCompositionChanged
- OnEnterMenuLoop
- OnEnterSizeMove
- OnEraseBkgnd
- OnExitMenuLoop
- OnExitSizeMove
- OnGetMinMaxInfo
- OnGetObject
- OnImeMessages
- OnInitMenu
- OnInputLangChange
- OnKeyEvent
- OnKillFocus
- OnMouseActivate
- OnMouseRange
- OnMove
- OnMoving
- OnNCActivate
- OnNCCalcSize
- OnNCHitTest
- OnNCPaint
- OnNCUAHDrawCaption
- OnNCUAHDrawFrame
- OnNotify
- OnPaint
- OnReflectedMessage
- OnScrollMessage
- OnSessionChange
- OnSetCursor
- OnSetFocus
- OnSetIcon
- OnSetText
- OnSettingChange
- OnSize
- OnSysCommand
- OnThemeChanged
- OnTouchEvent
- OnWindowPosChanging
- OnWindowPosChanged
- HandleTouchEvents
- ResetTouchDownContext
- HandleMouseEventInternal
- IsSynthesizedMouseMessage
#include "ui/views/win/hwnd_message_handler.h"
#include <dwmapi.h>
#include <oleacc.h>
#include <shellapi.h>
#include <wtsapi32.h>
#pragma comment(lib, "wtsapi32.lib")
#include "base/bind.h"
#include "base/debug/trace_event.h"
#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "ui/base/touch/touch_enabled.h"
#include "ui/base/view_prop.h"
#include "ui/base/win/internal_constants.h"
#include "ui/base/win/lock_state.h"
#include "ui/base/win/mouse_wheel_util.h"
#include "ui/base/win/shell.h"
#include "ui/base/win/touch_input.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/gestures/gesture_sequence.h"
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/path.h"
#include "ui/gfx/path_win.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/win/dpi.h"
#include "ui/gfx/win/hwnd_util.h"
#include "ui/native_theme/native_theme_win.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/monitor_win.h"
#include "ui/views/widget/widget_hwnd_utils.h"
#include "ui/views/win/appbar.h"
#include "ui/views/win/fullscreen_handler.h"
#include "ui/views/win/hwnd_message_handler_delegate.h"
#include "ui/views/win/scoped_fullscreen_visibility.h"
namespace views {
namespace {
class MoveLoopMouseWatcher {
public:
MoveLoopMouseWatcher(HWNDMessageHandler* host, bool hide_on_escape);
~MoveLoopMouseWatcher();
bool got_mouse_up() const { return got_mouse_up_; }
private:
static MoveLoopMouseWatcher* instance_;
static LRESULT CALLBACK MouseHook(int n_code, WPARAM w_param, LPARAM l_param);
static LRESULT CALLBACK KeyHook(int n_code, WPARAM w_param, LPARAM l_param);
void Unhook();
HWNDMessageHandler* host_;
const bool hide_on_escape_;
bool got_mouse_up_;
HHOOK mouse_hook_;
HHOOK key_hook_;
DISALLOW_COPY_AND_ASSIGN(MoveLoopMouseWatcher);
};
MoveLoopMouseWatcher* MoveLoopMouseWatcher::instance_ = NULL;
MoveLoopMouseWatcher::MoveLoopMouseWatcher(HWNDMessageHandler* host,
bool hide_on_escape)
: host_(host),
hide_on_escape_(hide_on_escape),
got_mouse_up_(false),
mouse_hook_(NULL),
key_hook_(NULL) {
if (instance_)
instance_->Unhook();
mouse_hook_ = SetWindowsHookEx(
WH_MOUSE, &MouseHook, NULL, GetCurrentThreadId());
if (mouse_hook_) {
instance_ = this;
key_hook_ = SetWindowsHookEx(
WH_KEYBOARD, &KeyHook, NULL, GetCurrentThreadId());
}
if (instance_ != this) {
got_mouse_up_ = true;
}
}
MoveLoopMouseWatcher::~MoveLoopMouseWatcher() {
Unhook();
}
void MoveLoopMouseWatcher::Unhook() {
if (instance_ != this)
return;
DCHECK(mouse_hook_);
UnhookWindowsHookEx(mouse_hook_);
if (key_hook_)
UnhookWindowsHookEx(key_hook_);
key_hook_ = NULL;
mouse_hook_ = NULL;
instance_ = NULL;
}
LRESULT CALLBACK MoveLoopMouseWatcher::MouseHook(int n_code,
WPARAM w_param,
LPARAM l_param) {
DCHECK(instance_);
if (n_code == HC_ACTION && w_param == WM_LBUTTONUP)
instance_->got_mouse_up_ = true;
return CallNextHookEx(instance_->mouse_hook_, n_code, w_param, l_param);
}
LRESULT CALLBACK MoveLoopMouseWatcher::KeyHook(int n_code,
WPARAM w_param,
LPARAM l_param) {
if (n_code == HC_ACTION && w_param == VK_ESCAPE) {
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
int value = TRUE;
HRESULT result = DwmSetWindowAttribute(
instance_->host_->hwnd(),
DWMWA_TRANSITIONS_FORCEDISABLED,
&value,
sizeof(value));
}
if (instance_->hide_on_escape_)
instance_->host_->Hide();
}
return CallNextHookEx(instance_->key_hook_, n_code, w_param, l_param);
}
BOOL CALLBACK EnumChildWindowsForRedraw(HWND hwnd, LPARAM lparam) {
DWORD process_id;
GetWindowThreadProcessId(hwnd, &process_id);
int flags = RDW_INVALIDATE | RDW_NOCHILDREN | RDW_FRAME;
if (process_id == GetCurrentProcessId())
flags |= RDW_UPDATENOW;
RedrawWindow(hwnd, NULL, NULL, flags);
return TRUE;
}
bool GetMonitorAndRects(const RECT& rect,
HMONITOR* monitor,
gfx::Rect* monitor_rect,
gfx::Rect* work_area) {
DCHECK(monitor);
DCHECK(monitor_rect);
DCHECK(work_area);
*monitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONULL);
if (!*monitor)
return false;
MONITORINFO monitor_info = { 0 };
monitor_info.cbSize = sizeof(monitor_info);
GetMonitorInfo(*monitor, &monitor_info);
*monitor_rect = gfx::Rect(monitor_info.rcMonitor);
*work_area = gfx::Rect(monitor_info.rcWork);
return true;
}
struct FindOwnedWindowsData {
HWND window;
std::vector<Widget*> owned_widgets;
};
void EnableMenuItemByCommand(HMENU menu, UINT command, bool enabled) {
UINT flags = MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_DISABLED | MF_GRAYED);
EnableMenuItem(menu, command, flags);
}
BOOL CALLBACK SendDwmCompositionChanged(HWND window, LPARAM param) {
SendMessage(window, WM_DWMCOMPOSITIONCHANGED, 0, 0);
return TRUE;
}
struct ClipState {
HWND parent;
HDC dc;
int x;
int y;
};
static BOOL CALLBACK ClipDCToChild(HWND window, LPARAM param) {
ClipState* clip_state = reinterpret_cast<ClipState*>(param);
if (GetParent(window) == clip_state->parent && IsWindowVisible(window)) {
RECT bounds;
GetWindowRect(window, &bounds);
ExcludeClipRect(clip_state->dc,
bounds.left - clip_state->x,
bounds.top - clip_state->y,
bounds.right - clip_state->x,
bounds.bottom - clip_state->y);
}
return TRUE;
}
const int kAutoHideTaskbarThicknessPx = 2;
bool IsTopLevelWindow(HWND window) {
long style = ::GetWindowLong(window, GWL_STYLE);
if (!(style & WS_CHILD))
return true;
HWND parent = ::GetParent(window);
return !parent || (parent == ::GetDesktopWindow());
}
void AddScrollStylesToWindow(HWND window) {
if (::IsWindow(window)) {
long current_style = ::GetWindowLong(window, GWL_STYLE);
::SetWindowLong(window, GWL_STYLE,
current_style | WS_VSCROLL | WS_HSCROLL);
}
}
const int kTouchDownContextResetTimeout = 500;
const int kSynthesizedMouseTouchMessagesTimeDifference = 500;
}
class HWNDMessageHandler::ScopedRedrawLock {
public:
explicit ScopedRedrawLock(HWNDMessageHandler* owner)
: owner_(owner),
hwnd_(owner_->hwnd()),
was_visible_(owner_->IsVisible()),
cancel_unlock_(false),
force_(!(GetWindowLong(hwnd_, GWL_STYLE) & WS_CAPTION)) {
if (was_visible_ && ::IsWindow(hwnd_))
owner_->LockUpdates(force_);
}
~ScopedRedrawLock() {
if (!cancel_unlock_ && was_visible_ && ::IsWindow(hwnd_))
owner_->UnlockUpdates(force_);
}
void CancelUnlockOperation() { cancel_unlock_ = true; }
private:
HWNDMessageHandler* owner_;
HWND hwnd_;
bool was_visible_;
bool cancel_unlock_;
bool force_;
DISALLOW_COPY_AND_ASSIGN(ScopedRedrawLock);
};
long HWNDMessageHandler::last_touch_message_time_ = 0;
HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate)
: delegate_(delegate),
fullscreen_handler_(new FullscreenHandler),
weak_factory_(this),
waiting_for_close_now_(false),
remove_standard_frame_(false),
use_system_default_icon_(false),
restore_focus_when_enabled_(false),
restored_enabled_(false),
current_cursor_(NULL),
previous_cursor_(NULL),
active_mouse_tracking_flags_(0),
is_right_mouse_pressed_on_caption_(false),
lock_updates_count_(0),
ignore_window_pos_changes_(false),
last_monitor_(NULL),
use_layered_buffer_(false),
layered_alpha_(255),
waiting_for_redraw_layered_window_contents_(false),
is_first_nccalc_(true),
menu_depth_(0),
autohide_factory_(this),
id_generator_(0),
needs_scroll_styles_(false),
in_size_loop_(false),
touch_down_context_(false) {
}
HWNDMessageHandler::~HWNDMessageHandler() {
delegate_ = NULL;
ClearUserData();
}
void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
TRACE_EVENT0("views", "HWNDMessageHandler::Init");
GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
&last_work_area_);
WindowImpl::Init(parent, bounds);
#if defined(ENABLE_SCROLL_HACK)
if (IsTopLevelWindow(hwnd())) {
long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
if (!(current_style & WS_POPUP)) {
AddScrollStylesToWindow(hwnd());
needs_scroll_styles_ = true;
}
}
#endif
prop_window_target_.reset(new ui::ViewProp(hwnd(),
ui::WindowEventTarget::kWin32InputEventTarget,
static_cast<ui::WindowEventTarget*>(this)));
}
void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) {
if (modal_type == ui::MODAL_TYPE_NONE)
return;
HWND start = ::GetWindow(hwnd(), GW_OWNER);
while (start) {
::EnableWindow(start, FALSE);
start = ::GetParent(start);
}
}
void HWNDMessageHandler::Close() {
if (!IsWindow(hwnd()))
return;
Hide();
RestoreEnabledIfNecessary();
if (!waiting_for_close_now_) {
waiting_for_close_now_ = true;
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::CloseNow, weak_factory_.GetWeakPtr()));
}
}
void HWNDMessageHandler::CloseNow() {
waiting_for_close_now_ = false;
if (IsWindow(hwnd()))
DestroyWindow(hwnd());
}
gfx::Rect HWNDMessageHandler::GetWindowBoundsInScreen() const {
RECT r;
GetWindowRect(hwnd(), &r);
return gfx::Rect(r);
}
gfx::Rect HWNDMessageHandler::GetClientAreaBoundsInScreen() const {
RECT r;
GetClientRect(hwnd(), &r);
POINT point = { r.left, r.top };
ClientToScreen(hwnd(), &point);
return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
}
gfx::Rect HWNDMessageHandler::GetRestoredBounds() const {
if (fullscreen_handler_->fullscreen())
return fullscreen_handler_->GetRestoreBounds();
gfx::Rect bounds;
GetWindowPlacement(&bounds, NULL);
return bounds;
}
gfx::Rect HWNDMessageHandler::GetClientAreaBounds() const {
if (IsMinimized())
return gfx::Rect();
if (delegate_->WidgetSizeIsClientSize())
return GetClientAreaBoundsInScreen();
return GetWindowBoundsInScreen();
}
void HWNDMessageHandler::GetWindowPlacement(
gfx::Rect* bounds,
ui::WindowShowState* show_state) const {
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
const bool succeeded = !!::GetWindowPlacement(hwnd(), &wp);
DCHECK(succeeded);
if (bounds != NULL) {
if (wp.showCmd == SW_SHOWNORMAL) {
const bool succeeded = GetWindowRect(hwnd(), &wp.rcNormalPosition) != 0;
DCHECK(succeeded);
*bounds = gfx::Rect(wp.rcNormalPosition);
} else {
MONITORINFO mi;
mi.cbSize = sizeof(mi);
const bool succeeded = GetMonitorInfo(
MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi) != 0;
DCHECK(succeeded);
*bounds = gfx::Rect(wp.rcNormalPosition);
bounds->Offset(mi.rcWork.left - mi.rcMonitor.left,
mi.rcWork.top - mi.rcMonitor.top);
}
}
if (show_state) {
if (wp.showCmd == SW_SHOWMAXIMIZED)
*show_state = ui::SHOW_STATE_MAXIMIZED;
else if (wp.showCmd == SW_SHOWMINIMIZED)
*show_state = ui::SHOW_STATE_MINIMIZED;
else
*show_state = ui::SHOW_STATE_NORMAL;
}
}
void HWNDMessageHandler::SetBounds(const gfx::Rect& bounds_in_pixels) {
LONG style = GetWindowLong(hwnd(), GWL_STYLE);
if (style & WS_MAXIMIZE)
SetWindowLong(hwnd(), GWL_STYLE, style & ~WS_MAXIMIZE);
SetWindowPos(hwnd(), NULL, bounds_in_pixels.x(), bounds_in_pixels.y(),
bounds_in_pixels.width(), bounds_in_pixels.height(),
SWP_NOACTIVATE | SWP_NOZORDER);
}
void HWNDMessageHandler::SetSize(const gfx::Size& size) {
SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(),
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
}
void HWNDMessageHandler::CenterWindow(const gfx::Size& size) {
HWND parent = GetParent(hwnd());
if (!IsWindow(hwnd()))
parent = ::GetWindow(hwnd(), GW_OWNER);
gfx::CenterAndSizeWindow(parent, hwnd(), size);
}
void HWNDMessageHandler::SetRegion(HRGN region) {
custom_window_region_.Set(region);
ResetWindowRegion(false, true);
UpdateDwmNcRenderingPolicy();
}
void HWNDMessageHandler::StackAbove(HWND other_hwnd) {
SetWindowPos(hwnd(), other_hwnd, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
void HWNDMessageHandler::StackAtTop() {
SetWindowPos(hwnd(), HWND_TOP, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
void HWNDMessageHandler::Show() {
if (IsWindow(hwnd())) {
if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) &&
!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) {
ShowWindowWithState(ui::SHOW_STATE_NORMAL);
} else {
ShowWindowWithState(ui::SHOW_STATE_INACTIVE);
}
}
}
void HWNDMessageHandler::ShowWindowWithState(ui::WindowShowState show_state) {
TRACE_EVENT0("views", "HWNDMessageHandler::ShowWindowWithState");
DWORD native_show_state;
switch (show_state) {
case ui::SHOW_STATE_INACTIVE:
native_show_state = SW_SHOWNOACTIVATE;
break;
case ui::SHOW_STATE_MAXIMIZED:
native_show_state = SW_SHOWMAXIMIZED;
break;
case ui::SHOW_STATE_MINIMIZED:
native_show_state = SW_SHOWMINIMIZED;
break;
default:
native_show_state = delegate_->GetInitialShowState();
break;
}
ShowWindow(hwnd(), native_show_state);
if (native_show_state == SW_HIDE) {
native_show_state = SW_SHOWNORMAL;
ShowWindow(hwnd(), native_show_state);
}
if (native_show_state == SW_SHOWNORMAL ||
native_show_state == SW_SHOWMAXIMIZED)
Activate();
if (!delegate_->HandleInitialFocus(show_state))
SetInitialFocus();
}
void HWNDMessageHandler::ShowMaximizedWithBounds(const gfx::Rect& bounds) {
WINDOWPLACEMENT placement = { 0 };
placement.length = sizeof(WINDOWPLACEMENT);
placement.showCmd = SW_SHOWMAXIMIZED;
placement.rcNormalPosition = bounds.ToRECT();
SetWindowPlacement(hwnd(), &placement);
}
void HWNDMessageHandler::Hide() {
if (IsWindow(hwnd())) {
SetWindowPos(hwnd(), NULL, 0, 0, 0, 0,
SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
}
}
void HWNDMessageHandler::Maximize() {
ExecuteSystemMenuCommand(SC_MAXIMIZE);
}
void HWNDMessageHandler::Minimize() {
ExecuteSystemMenuCommand(SC_MINIMIZE);
delegate_->HandleNativeBlur(NULL);
}
void HWNDMessageHandler::Restore() {
ExecuteSystemMenuCommand(SC_RESTORE);
}
void HWNDMessageHandler::Activate() {
if (IsMinimized())
::ShowWindow(hwnd(), SW_RESTORE);
::SetWindowPos(hwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
SetForegroundWindow(hwnd());
}
void HWNDMessageHandler::Deactivate() {
HWND next_hwnd = ::GetNextWindow(hwnd(), GW_HWNDNEXT);
while (next_hwnd) {
if (::IsWindowVisible(next_hwnd)) {
::SetForegroundWindow(next_hwnd);
return;
}
next_hwnd = ::GetNextWindow(next_hwnd, GW_HWNDNEXT);
}
}
void HWNDMessageHandler::SetAlwaysOnTop(bool on_top) {
::SetWindowPos(hwnd(), on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
bool HWNDMessageHandler::IsVisible() const {
return !!::IsWindowVisible(hwnd());
}
bool HWNDMessageHandler::IsActive() const {
return GetActiveWindow() == hwnd();
}
bool HWNDMessageHandler::IsMinimized() const {
return !!::IsIconic(hwnd());
}
bool HWNDMessageHandler::IsMaximized() const {
return !!::IsZoomed(hwnd());
}
bool HWNDMessageHandler::IsAlwaysOnTop() const {
return (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
}
bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset,
bool hide_on_escape) {
ReleaseCapture();
MoveLoopMouseWatcher watcher(this, hide_on_escape);
base::MessageLoop::ScopedNestableTaskAllower allow_nested(
base::MessageLoop::current());
SendMessage(hwnd(), WM_SYSCOMMAND, SC_MOVE | 0x0002, GetMessagePos());
return watcher.got_mouse_up();
}
void HWNDMessageHandler::EndMoveLoop() {
SendMessage(hwnd(), WM_CANCELMODE, 0, 0);
}
void HWNDMessageHandler::SendFrameChanged() {
SetWindowPos(hwnd(), NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
}
void HWNDMessageHandler::FlashFrame(bool flash) {
FLASHWINFO fwi;
fwi.cbSize = sizeof(fwi);
fwi.hwnd = hwnd();
if (flash) {
fwi.dwFlags = FLASHW_ALL;
fwi.uCount = 4;
fwi.dwTimeout = 0;
} else {
fwi.dwFlags = FLASHW_STOP;
}
FlashWindowEx(&fwi);
}
void HWNDMessageHandler::ClearNativeFocus() {
::SetFocus(hwnd());
}
void HWNDMessageHandler::SetCapture() {
DCHECK(!HasCapture());
::SetCapture(hwnd());
}
void HWNDMessageHandler::ReleaseCapture() {
if (HasCapture())
::ReleaseCapture();
}
bool HWNDMessageHandler::HasCapture() const {
return ::GetCapture() == hwnd();
}
void HWNDMessageHandler::SetVisibilityChangedAnimationsEnabled(bool enabled) {
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
int dwm_value = enabled ? FALSE : TRUE;
DwmSetWindowAttribute(
hwnd(), DWMWA_TRANSITIONS_FORCEDISABLED, &dwm_value, sizeof(dwm_value));
}
}
bool HWNDMessageHandler::SetTitle(const base::string16& title) {
base::string16 current_title;
size_t len_with_null = GetWindowTextLength(hwnd()) + 1;
if (len_with_null == 1 && title.length() == 0)
return false;
if (len_with_null - 1 == title.length() &&
GetWindowText(
hwnd(), WriteInto(¤t_title, len_with_null), len_with_null) &&
current_title == title)
return false;
SetWindowText(hwnd(), title.c_str());
return true;
}
void HWNDMessageHandler::SetCursor(HCURSOR cursor) {
if (cursor) {
previous_cursor_ = ::SetCursor(cursor);
current_cursor_ = cursor;
} else if (previous_cursor_) {
::SetCursor(previous_cursor_);
previous_cursor_ = NULL;
}
}
void HWNDMessageHandler::FrameTypeChanged() {
UpdateDwmNcRenderingPolicy();
ResetWindowRegion(true, false);
delegate_->HandleFrameChanged();
if (IsVisible() && !delegate_->IsUsingCustomFrame()) {
UINT flags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER;
SetWindowPos(hwnd(), NULL, 0, 0, 0, 0, flags | SWP_HIDEWINDOW);
SetWindowPos(hwnd(), NULL, 0, 0, 0, 0, flags | SWP_SHOWWINDOW);
::InvalidateRect(hwnd(), NULL, FALSE);
}
EnumChildWindows(hwnd(), &SendDwmCompositionChanged, NULL);
}
void HWNDMessageHandler::SchedulePaintInRect(const gfx::Rect& rect) {
if (use_layered_buffer_) {
invalid_rect_.Union(rect);
if (!waiting_for_redraw_layered_window_contents_) {
waiting_for_redraw_layered_window_contents_ = true;
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::RedrawLayeredWindowContents,
weak_factory_.GetWeakPtr()));
}
} else {
RECT r = rect.ToRECT();
InvalidateRect(hwnd(), &r, FALSE);
}
}
void HWNDMessageHandler::SetOpacity(BYTE opacity) {
layered_alpha_ = opacity;
}
void HWNDMessageHandler::SetWindowIcons(const gfx::ImageSkia& window_icon,
const gfx::ImageSkia& app_icon) {
if (!window_icon.isNull()) {
HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(
*window_icon.bitmap());
HICON old_icon = reinterpret_cast<HICON>(
SendMessage(hwnd(), WM_SETICON, ICON_SMALL,
reinterpret_cast<LPARAM>(windows_icon)));
if (old_icon)
DestroyIcon(old_icon);
}
if (!app_icon.isNull()) {
HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(*app_icon.bitmap());
HICON old_icon = reinterpret_cast<HICON>(
SendMessage(hwnd(), WM_SETICON, ICON_BIG,
reinterpret_cast<LPARAM>(windows_icon)));
if (old_icon)
DestroyIcon(old_icon);
}
}
void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
SetMsgHandled(delegate_->HandleKeyEvent(key));
}
HICON HWNDMessageHandler::GetDefaultWindowIcon() const {
if (use_system_default_icon_)
return NULL;
return ViewsDelegate::views_delegate ?
ViewsDelegate::views_delegate->GetDefaultWindowIcon() : NULL;
}
LRESULT HWNDMessageHandler::OnWndProc(UINT message,
WPARAM w_param,
LPARAM l_param) {
HWND window = hwnd();
LRESULT result = 0;
if (delegate_ && delegate_->PreHandleMSG(message, w_param, l_param, &result))
return result;
const BOOL old_msg_handled = msg_handled_;
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
const BOOL processed =
_ProcessWindowMessage(window, message, w_param, l_param, result, 0);
if (!ref)
return 0;
msg_handled_ = old_msg_handled;
if (!processed)
result = DefWindowProc(window, message, w_param, l_param);
if (!::IsWindow(window))
return result;
if (delegate_)
delegate_->PostHandleMSG(message, w_param, l_param);
if (message == WM_NCDESTROY) {
if (delegate_)
delegate_->HandleDestroyed();
}
if (message == WM_ACTIVATE && delegate_->CanSaveFocus())
PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param));
if (message == WM_ENABLE && restore_focus_when_enabled_) {
DCHECK(delegate_->CanSaveFocus());
restore_focus_when_enabled_ = false;
delegate_->RestoreFocusOnEnable();
}
return result;
}
LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param) {
return HandleMouseEventInternal(message, w_param, l_param, false);
}
LRESULT HWNDMessageHandler::HandleTouchMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param) {
return OnTouchEvent(message, w_param, l_param);
}
LRESULT HWNDMessageHandler::HandleKeyboardMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param) {
return OnKeyEvent(message, w_param, l_param);
}
LRESULT HWNDMessageHandler::HandleScrollMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param) {
return OnScrollMessage(message, w_param, l_param);
}
LRESULT HWNDMessageHandler::HandleNcHitTestMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param) {
return OnNCHitTest(
gfx::Point(CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param)));
}
int HWNDMessageHandler::GetAppbarAutohideEdges(HMONITOR monitor) {
autohide_factory_.InvalidateWeakPtrs();
return Appbar::instance()->GetAutohideEdges(
monitor,
base::Bind(&HWNDMessageHandler::OnAppbarAutohideEdgesChanged,
autohide_factory_.GetWeakPtr()));
}
void HWNDMessageHandler::OnAppbarAutohideEdgesChanged() {
RECT client;
GetWindowRect(hwnd(), &client);
SetWindowPos(hwnd(), NULL, client.left, client.top,
client.right - client.left, client.bottom - client.top,
SWP_FRAMECHANGED);
}
void HWNDMessageHandler::SetInitialFocus() {
if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) &&
!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) {
SetFocus(hwnd());
}
}
void HWNDMessageHandler::PostProcessActivateMessage(int activation_state,
bool minimized) {
DCHECK(delegate_->CanSaveFocus());
bool active = activation_state != WA_INACTIVE && !minimized;
if (delegate_->CanActivate())
delegate_->HandleActivationChanged(active);
if (!active) {
restore_focus_when_enabled_ = false;
delegate_->SaveFocusOnDeactivate();
} else {
if (!IsWindowEnabled(hwnd())) {
DCHECK(!restore_focus_when_enabled_);
restore_focus_when_enabled_ = true;
return;
}
delegate_->RestoreFocusOnActivate();
}
}
void HWNDMessageHandler::RestoreEnabledIfNecessary() {
if (delegate_->IsModal() && !restored_enabled_) {
restored_enabled_ = true;
HWND start = ::GetWindow(hwnd(), GW_OWNER);
while (start) {
::EnableWindow(start, TRUE);
start = ::GetParent(start);
}
}
}
void HWNDMessageHandler::ExecuteSystemMenuCommand(int command) {
if (command)
SendMessage(hwnd(), WM_SYSCOMMAND, command, 0);
}
void HWNDMessageHandler::TrackMouseEvents(DWORD mouse_tracking_flags) {
if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) {
if (mouse_tracking_flags & TME_CANCEL) {
active_mouse_tracking_flags_ = 0;
} else {
active_mouse_tracking_flags_ = mouse_tracking_flags;
}
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = mouse_tracking_flags;
tme.hwndTrack = hwnd();
tme.dwHoverTime = 0;
TrackMouseEvent(&tme);
} else if (mouse_tracking_flags != active_mouse_tracking_flags_) {
TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL);
TrackMouseEvents(mouse_tracking_flags);
}
}
void HWNDMessageHandler::ClientAreaSizeChanged() {
gfx::Size s = GetClientAreaBounds().size();
delegate_->HandleClientSizeChanged(s);
if (use_layered_buffer_)
layered_window_contents_.reset(new gfx::Canvas(s, 1.0f, false));
}
bool HWNDMessageHandler::GetClientAreaInsets(gfx::Insets* insets) const {
if (delegate_->GetClientAreaInsets(insets))
return true;
DCHECK(insets->empty());
if (!delegate_->IsWidgetWindow() ||
(!delegate_->IsUsingCustomFrame() && !remove_standard_frame_)) {
return false;
}
if (IsMaximized()) {
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
if (remove_standard_frame_)
border_thickness -= 1;
*insets = gfx::Insets(
border_thickness, border_thickness, border_thickness, border_thickness);
return true;
}
*insets = gfx::Insets();
return true;
}
void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) {
if ((window_ex_style() & WS_EX_COMPOSITED) == 0 && !custom_window_region_ &&
(!delegate_->IsUsingCustomFrame() || !delegate_->IsWidgetWindow())) {
if (force)
SetWindowRgn(hwnd(), NULL, redraw);
return;
}
HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
int current_rgn_result = GetWindowRgn(hwnd(), current_rgn);
RECT window_rect;
GetWindowRect(hwnd(), &window_rect);
HRGN new_region;
if (custom_window_region_) {
new_region = ::CreateRectRgn(0, 0, 0, 0);
::CombineRgn(new_region, custom_window_region_.Get(), NULL, RGN_COPY);
} else if (IsMaximized()) {
HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof mi;
GetMonitorInfo(monitor, &mi);
RECT work_rect = mi.rcWork;
OffsetRect(&work_rect, -window_rect.left, -window_rect.top);
new_region = CreateRectRgnIndirect(&work_rect);
} else {
gfx::Path window_mask;
delegate_->GetWindowMask(gfx::Size(window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top),
&window_mask);
new_region = gfx::CreateHRGNFromSkPath(window_mask);
}
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
SetWindowRgn(hwnd(), new_region, redraw);
} else {
DeleteObject(new_region);
}
DeleteObject(current_rgn);
}
void HWNDMessageHandler::UpdateDwmNcRenderingPolicy() {
if (base::win::GetVersion() < base::win::VERSION_VISTA)
return;
DWMNCRENDERINGPOLICY policy =
custom_window_region_ || delegate_->IsUsingCustomFrame() ?
DWMNCRP_DISABLED : DWMNCRP_ENABLED;
DwmSetWindowAttribute(hwnd(), DWMWA_NCRENDERING_POLICY,
&policy, sizeof(DWMNCRENDERINGPOLICY));
}
LRESULT HWNDMessageHandler::DefWindowProcWithRedrawLock(UINT message,
WPARAM w_param,
LPARAM l_param) {
ScopedRedrawLock lock(this);
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
LRESULT result = DefWindowProc(hwnd(), message, w_param, l_param);
if (!ref)
lock.CancelUnlockOperation();
return result;
}
void HWNDMessageHandler::LockUpdates(bool force) {
if ((force || !ui::win::IsAeroGlassEnabled()) && ++lock_updates_count_ == 1) {
SetWindowLong(hwnd(), GWL_STYLE,
GetWindowLong(hwnd(), GWL_STYLE) & ~WS_VISIBLE);
}
}
void HWNDMessageHandler::UnlockUpdates(bool force) {
if ((force || !ui::win::IsAeroGlassEnabled()) && --lock_updates_count_ <= 0) {
SetWindowLong(hwnd(), GWL_STYLE,
GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE);
lock_updates_count_ = 0;
}
}
void HWNDMessageHandler::RedrawLayeredWindowContents() {
waiting_for_redraw_layered_window_contents_ = false;
if (invalid_rect_.IsEmpty())
return;
layered_window_contents_->sk_canvas()->save();
double scale = gfx::win::GetDeviceScaleFactor();
layered_window_contents_->sk_canvas()->scale(
SkScalar(scale),SkScalar(scale));
layered_window_contents_->ClipRect(invalid_rect_);
delegate_->PaintLayeredWindow(layered_window_contents_.get());
layered_window_contents_->sk_canvas()->scale(
SkScalar(1.0/scale),SkScalar(1.0/scale));
layered_window_contents_->sk_canvas()->restore();
RECT wr;
GetWindowRect(hwnd(), &wr);
SIZE size = {wr.right - wr.left, wr.bottom - wr.top};
POINT position = {wr.left, wr.top};
HDC dib_dc = skia::BeginPlatformPaint(layered_window_contents_->sk_canvas());
POINT zero = {0, 0};
BLENDFUNCTION blend = {AC_SRC_OVER, 0, layered_alpha_, AC_SRC_ALPHA};
UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero,
RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
invalid_rect_.SetRect(0, 0, 0, 0);
skia::EndPlatformPaint(layered_window_contents_->sk_canvas());
}
void HWNDMessageHandler::ForceRedrawWindow(int attempts) {
if (ui::IsWorkstationLocked()) {
if (--attempts <= 0)
return;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::ForceRedrawWindow,
weak_factory_.GetWeakPtr(),
attempts),
base::TimeDelta::FromMilliseconds(500));
return;
}
InvalidateRect(hwnd(), NULL, FALSE);
}
void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) {
if (delegate_->IsWidgetWindow() && !active &&
thread_id != GetCurrentThreadId()) {
delegate_->HandleAppDeactivated();
if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame())
DefWindowProcWithRedrawLock(WM_NCACTIVATE, FALSE, 0);
}
}
BOOL HWNDMessageHandler::OnAppCommand(HWND window,
short command,
WORD device,
int keystate) {
BOOL handled = !!delegate_->HandleAppCommand(command);
SetMsgHandled(handled);
return handled;
}
void HWNDMessageHandler::OnCancelMode() {
delegate_->HandleCancelMode();
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 (notification_code > 1 || delegate_->HandleAppCommand(command))
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
use_layered_buffer_ = !!(window_ex_style() & WS_EX_LAYERED);
if (window_ex_style() & WS_EX_COMPOSITED) {
if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
MARGINS margins = {-1,-1,-1,-1};
DwmExtendFrameIntoClientArea(hwnd(), &margins);
}
}
fullscreen_handler_->set_hwnd(hwnd());
SendMessage(hwnd(),
WM_CHANGEUISTATE,
MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS),
0);
if (remove_standard_frame_) {
SetWindowLong(hwnd(), GWL_STYLE,
GetWindowLong(hwnd(), GWL_STYLE) & ~WS_CAPTION);
SendFrameChanged();
}
GetSystemMenu(hwnd(), false);
if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
ui::AreTouchEventsEnabled())
RegisterTouchWindow(hwnd(), TWF_WANTPALM);
ClientAreaSizeChanged();
delegate_->HandleCreate();
WTSRegisterSessionNotification(hwnd(), NOTIFY_FOR_THIS_SESSION);
return 0;
}
void HWNDMessageHandler::OnDestroy() {
WTSUnRegisterSessionNotification(hwnd());
delegate_->HandleDestroying();
}
void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel,
const gfx::Size& screen_size) {
delegate_->HandleDisplayChange();
}
LRESULT HWNDMessageHandler::OnDwmCompositionChanged(UINT msg,
WPARAM w_param,
LPARAM l_param) {
if (!delegate_->IsWidgetWindow()) {
SetMsgHandled(FALSE);
return 0;
}
FrameTypeChanged();
return 0;
}
void HWNDMessageHandler::OnEnterMenuLoop(BOOL from_track_popup_menu) {
if (menu_depth_++ == 0)
delegate_->HandleMenuLoop(true);
}
void HWNDMessageHandler::OnEnterSizeMove() {
if (in_size_loop_ && needs_scroll_styles_)
ShowScrollBar(hwnd(), SB_BOTH, FALSE);
delegate_->HandleBeginWMSizeMove();
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnEraseBkgnd(HDC dc) {
return 1;
}
void HWNDMessageHandler::OnExitMenuLoop(BOOL is_shortcut_menu) {
if (--menu_depth_ == 0)
delegate_->HandleMenuLoop(false);
DCHECK_GE(0, menu_depth_);
}
void HWNDMessageHandler::OnExitSizeMove() {
delegate_->HandleEndWMSizeMove();
SetMsgHandled(FALSE);
if (in_size_loop_ && needs_scroll_styles_)
AddScrollStylesToWindow(hwnd());
}
void HWNDMessageHandler::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
gfx::Size min_window_size;
gfx::Size max_window_size;
delegate_->GetMinMaxSize(&min_window_size, &max_window_size);
if (delegate_->WidgetSizeIsClientSize()) {
RECT client_rect, window_rect;
GetClientRect(hwnd(), &client_rect);
GetWindowRect(hwnd(), &window_rect);
CR_DEFLATE_RECT(&window_rect, &client_rect);
min_window_size.Enlarge(window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top);
if (!max_window_size.IsEmpty()) {
max_window_size.Enlarge(window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top);
}
}
minmax_info->ptMinTrackSize.x = min_window_size.width();
minmax_info->ptMinTrackSize.y = min_window_size.height();
if (max_window_size.width() || max_window_size.height()) {
if (!max_window_size.width())
max_window_size.set_width(GetSystemMetrics(SM_CXMAXTRACK));
if (!max_window_size.height())
max_window_size.set_height(GetSystemMetrics(SM_CYMAXTRACK));
minmax_info->ptMaxTrackSize.x = max_window_size.width();
minmax_info->ptMaxTrackSize.y = max_window_size.height();
}
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnGetObject(UINT message,
WPARAM w_param,
LPARAM l_param) {
LRESULT reference_result = static_cast<LRESULT>(0L);
if (OBJID_CLIENT == l_param) {
base::win::ScopedComPtr<IAccessible> root(
delegate_->GetNativeViewAccessible());
reference_result = LresultFromObject(IID_IAccessible, w_param,
static_cast<IAccessible*>(root.Detach()));
}
return reference_result;
}
LRESULT HWNDMessageHandler::OnImeMessages(UINT message,
WPARAM w_param,
LPARAM l_param) {
LRESULT result = 0;
SetMsgHandled(delegate_->HandleIMEMessage(
message, w_param, l_param, &result));
return result;
}
void HWNDMessageHandler::OnInitMenu(HMENU menu) {
bool is_fullscreen = fullscreen_handler_->fullscreen();
bool is_minimized = IsMinimized();
bool is_maximized = IsMaximized();
bool is_restored = !is_fullscreen && !is_minimized && !is_maximized;
ScopedRedrawLock lock(this);
EnableMenuItemByCommand(menu, SC_RESTORE, delegate_->CanResize() &&
(is_minimized || is_maximized));
EnableMenuItemByCommand(menu, SC_MOVE, is_restored);
EnableMenuItemByCommand(menu, SC_SIZE, delegate_->CanResize() && is_restored);
EnableMenuItemByCommand(menu, SC_MAXIMIZE, delegate_->CanMaximize() &&
!is_fullscreen && !is_maximized);
EnableMenuItemByCommand(menu, SC_MINIMIZE, delegate_->CanMaximize() &&
!is_minimized);
if (is_maximized && delegate_->CanResize())
::SetMenuDefaultItem(menu, SC_RESTORE, FALSE);
else if (!is_maximized && delegate_->CanMaximize())
::SetMenuDefaultItem(menu, SC_MAXIMIZE, FALSE);
}
void HWNDMessageHandler::OnInputLangChange(DWORD character_set,
HKL input_language_id) {
delegate_->HandleInputLanguageChange(character_set, input_language_id);
}
LRESULT HWNDMessageHandler::OnKeyEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() };
ui::KeyEvent key(msg, message == WM_CHAR);
if (!delegate_->HandleUntranslatedKeyEvent(key))
DispatchKeyEventPostIME(key);
return 0;
}
void HWNDMessageHandler::OnKillFocus(HWND focused_window) {
delegate_->HandleNativeBlur(focused_window);
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnMouseActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (touch_down_context_)
return MA_NOACTIVATE;
if (::GetProp(hwnd(), ui::kIgnoreTouchMouseActivateForWindow)) {
::RemoveProp(hwnd(), ui::kIgnoreTouchMouseActivateForWindow);
return MA_NOACTIVATE;
}
POINT cursor_pos = {0};
::GetCursorPos(&cursor_pos);
::ScreenToClient(hwnd(), &cursor_pos);
HWND child = ::RealChildWindowFromPoint(hwnd(), cursor_pos);
if (::IsWindow(child) && child != hwnd() && ::IsWindowVisible(child))
PostProcessActivateMessage(WA_INACTIVE, false);
if (delegate_->IsWidgetWindow())
return delegate_->CanActivate() ? MA_ACTIVATE : MA_NOACTIVATEANDEAT;
if (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)
return MA_NOACTIVATE;
SetMsgHandled(FALSE);
return MA_ACTIVATE;
}
LRESULT HWNDMessageHandler::OnMouseRange(UINT message,
WPARAM w_param,
LPARAM l_param) {
return HandleMouseEventInternal(message, w_param, l_param, true);
}
void HWNDMessageHandler::OnMove(const gfx::Point& point) {
delegate_->HandleMove();
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnMoving(UINT param, const RECT* new_bounds) {
delegate_->HandleMove();
}
LRESULT HWNDMessageHandler::OnNCActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
BOOL active = static_cast<BOOL>(LOWORD(w_param));
bool inactive_rendering_disabled = delegate_->IsInactiveRenderingDisabled();
if (!delegate_->IsWidgetWindow()) {
SetMsgHandled(FALSE);
return 0;
}
if (!delegate_->CanActivate())
return TRUE;
if (active && inactive_rendering_disabled)
delegate_->EnableInactiveRendering();
if (delegate_->IsUsingCustomFrame()) {
RedrawWindow(hwnd(), NULL, NULL,
RDW_NOCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW);
EnumChildWindows(hwnd(), EnumChildWindowsForRedraw, NULL);
}
if (IsVisible())
delegate_->SchedulePaint();
if (delegate_->IsUsingCustomFrame() &&
base::win::GetVersion() > base::win::VERSION_VISTA) {
SetMsgHandled(TRUE);
return TRUE;
}
return DefWindowProcWithRedrawLock(
WM_NCACTIVATE, inactive_rendering_disabled || active, 0);
}
LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) {
if (is_first_nccalc_) {
is_first_nccalc_ = false;
if (GetWindowLong(hwnd(), GWL_STYLE) & WS_CAPTION) {
SetMsgHandled(FALSE);
return 0;
}
}
gfx::Insets insets;
bool got_insets = GetClientAreaInsets(&insets);
if (!got_insets && !fullscreen_handler_->fullscreen() &&
!(mode && remove_standard_frame_)) {
SetMsgHandled(FALSE);
return 0;
}
RECT* client_rect = mode ?
&(reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0]) :
reinterpret_cast<RECT*>(l_param);
client_rect->left += insets.left();
client_rect->top += insets.top();
client_rect->bottom -= insets.bottom();
client_rect->right -= insets.right();
if (IsMaximized()) {
HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONULL);
if (!monitor) {
monitor = MonitorFromRect(client_rect, MONITOR_DEFAULTTONULL);
if (!monitor) {
return 0;
}
}
const int autohide_edges = GetAppbarAutohideEdges(monitor);
if (autohide_edges & Appbar::EDGE_LEFT)
client_rect->left += kAutoHideTaskbarThicknessPx;
if (autohide_edges & Appbar::EDGE_TOP) {
if (!delegate_->IsUsingCustomFrame()) {
--client_rect->bottom;
} else {
client_rect->top += kAutoHideTaskbarThicknessPx;
}
}
if (autohide_edges & Appbar::EDGE_RIGHT)
client_rect->right -= kAutoHideTaskbarThicknessPx;
if (autohide_edges & Appbar::EDGE_BOTTOM)
client_rect->bottom -= kAutoHideTaskbarThicknessPx;
return 0;
}
if (insets.left() == 0 || insets.top() == 0)
return 0;
return mode ? WVR_REDRAW : 0;
}
LRESULT HWNDMessageHandler::OnNCHitTest(const gfx::Point& point) {
if (!delegate_->IsWidgetWindow()) {
SetMsgHandled(FALSE);
return 0;
}
if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) {
LRESULT result;
if (DwmDefWindowProc(hwnd(), WM_NCHITTEST, 0,
MAKELPARAM(point.x(), point.y()), &result)) {
return result;
}
}
POINT temp = { point.x(), point.y() };
MapWindowPoints(HWND_DESKTOP, hwnd(), &temp, 1);
int component = delegate_->GetNonClientComponent(gfx::Point(temp));
if (component != HTNOWHERE)
return component;
LRESULT hit_test_code = DefWindowProc(hwnd(), WM_NCHITTEST, 0,
MAKELPARAM(point.x(), point.y()));
if (needs_scroll_styles_) {
switch (hit_test_code) {
case HTVSCROLL:
case HTHSCROLL:
hit_test_code = HTCLIENT;
break;
case HTBOTTOMRIGHT: {
int border_width = ::GetSystemMetrics(SM_CXSIZEFRAME);
int border_height = ::GetSystemMetrics(SM_CYSIZEFRAME);
int scroll_width = ::GetSystemMetrics(SM_CXVSCROLL);
int scroll_height = ::GetSystemMetrics(SM_CYVSCROLL);
RECT window_rect;
::GetWindowRect(hwnd(), &window_rect);
window_rect.bottom -= border_height;
window_rect.right -= border_width;
window_rect.left = window_rect.right - scroll_width;
window_rect.top = window_rect.bottom - scroll_height;
POINT pt;
pt.x = point.x();
pt.y = point.y();
if (::PtInRect(&window_rect, pt))
hit_test_code = HTCLIENT;
break;
}
default:
break;
}
}
return hit_test_code;
}
void HWNDMessageHandler::OnNCPaint(HRGN rgn) {
if (!delegate_->IsWidgetWindow() || !delegate_->IsUsingCustomFrame()) {
SetMsgHandled(FALSE);
return;
}
RECT window_rect;
GetWindowRect(hwnd(), &window_rect);
gfx::Size root_view_size = delegate_->GetRootViewSize();
if (gfx::Size(window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top) != root_view_size) {
return;
}
RECT dirty_region;
if (!rgn || rgn == reinterpret_cast<HRGN>(1)) {
dirty_region.left = 0;
dirty_region.top = 0;
dirty_region.right = window_rect.right - window_rect.left;
dirty_region.bottom = window_rect.bottom - window_rect.top;
} else {
RECT rgn_bounding_box;
GetRgnBox(rgn, &rgn_bounding_box);
if (!IntersectRect(&dirty_region, &rgn_bounding_box, &window_rect))
return;
OffsetRect(&dirty_region, -window_rect.left, -window_rect.top);
}
HDC dc = GetWindowDC(hwnd());
ClipState clip_state;
clip_state.x = window_rect.left;
clip_state.y = window_rect.top;
clip_state.parent = hwnd();
clip_state.dc = dc;
EnumChildWindows(hwnd(), &ClipDCToChild,
reinterpret_cast<LPARAM>(&clip_state));
gfx::Rect old_paint_region = invalid_rect_;
if (!old_paint_region.IsEmpty()) {
RECT old_paint_region_crect = old_paint_region.ToRECT();
RECT tmp = dirty_region;
UnionRect(&dirty_region, &tmp, &old_paint_region_crect);
}
SchedulePaintInRect(gfx::Rect(dirty_region));
if (!delegate_->HandlePaintAccelerated(gfx::Rect(dirty_region))) {
gfx::CanvasSkiaPaint canvas(dc,
true,
dirty_region.left,
dirty_region.top,
dirty_region.right - dirty_region.left,
dirty_region.bottom - dirty_region.top);
delegate_->HandlePaint(&canvas);
}
ReleaseDC(hwnd(), dc);
SetMsgHandled(delegate_->IsUsingCustomFrame());
}
LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message,
WPARAM w_param,
LPARAM l_param) {
SetMsgHandled(delegate_->IsUsingCustomFrame());
return 0;
}
LRESULT HWNDMessageHandler::OnNCUAHDrawFrame(UINT message,
WPARAM w_param,
LPARAM l_param) {
SetMsgHandled(delegate_->IsUsingCustomFrame());
return 0;
}
LRESULT HWNDMessageHandler::OnNotify(int w_param, NMHDR* l_param) {
LRESULT l_result = 0;
SetMsgHandled(delegate_->HandleTooltipNotify(w_param, l_param, &l_result));
return l_result;
}
void HWNDMessageHandler::OnPaint(HDC dc) {
PAINTSTRUCT ps;
HDC display_dc = BeginPaint(hwnd(), &ps);
CHECK(display_dc);
if (!IsRectEmpty(&ps.rcPaint) &&
!delegate_->HandlePaintAccelerated(gfx::Rect(ps.rcPaint))) {
delegate_->HandlePaint(NULL);
}
EndPaint(hwnd(), &ps);
}
LRESULT HWNDMessageHandler::OnReflectedMessage(UINT message,
WPARAM w_param,
LPARAM l_param) {
SetMsgHandled(FALSE);
return 0;
}
LRESULT HWNDMessageHandler::OnScrollMessage(UINT message,
WPARAM w_param,
LPARAM l_param) {
MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime() };
ui::ScrollEvent event(msg);
delegate_->HandleScrollEvent(event);
return 0;
}
void HWNDMessageHandler::OnSessionChange(WPARAM status_code,
PWTSSESSION_NOTIFICATION session_id) {
if (status_code == WTS_SESSION_UNLOCK)
ForceRedrawWindow(10);
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnSetCursor(UINT message,
WPARAM w_param,
LPARAM l_param) {
wchar_t* cursor = IDC_ARROW;
switch (LOWORD(l_param)) {
case HTSIZE:
cursor = IDC_SIZENWSE;
break;
case HTLEFT:
case HTRIGHT:
cursor = IDC_SIZEWE;
break;
case HTTOP:
case HTBOTTOM:
cursor = IDC_SIZENS;
break;
case HTTOPLEFT:
case HTBOTTOMRIGHT:
cursor = IDC_SIZENWSE;
break;
case HTTOPRIGHT:
case HTBOTTOMLEFT:
cursor = IDC_SIZENESW;
break;
case HTCLIENT:
SetCursor(current_cursor_);
return 1;
default:
break;
}
::SetCursor(LoadCursor(NULL, cursor));
return 1;
}
void HWNDMessageHandler::OnSetFocus(HWND last_focused_window) {
delegate_->HandleNativeFocus(last_focused_window);
SetMsgHandled(FALSE);
}
LRESULT HWNDMessageHandler::OnSetIcon(UINT size_type, HICON new_icon) {
return DefWindowProcWithRedrawLock(WM_SETICON, size_type,
reinterpret_cast<LPARAM>(new_icon));
}
LRESULT HWNDMessageHandler::OnSetText(const wchar_t* text) {
return DefWindowProcWithRedrawLock(WM_SETTEXT, NULL,
reinterpret_cast<LPARAM>(text));
}
void HWNDMessageHandler::OnSettingChange(UINT flags, const wchar_t* section) {
if (!GetParent(hwnd()) && (flags == SPI_SETWORKAREA) &&
!delegate_->WillProcessWorkAreaChange()) {
::SetWindowPos(hwnd(), 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
SWP_NOZORDER | SWP_NOREDRAW | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
SetMsgHandled(TRUE);
} else {
if (flags == SPI_SETWORKAREA)
delegate_->HandleWorkAreaChanged();
SetMsgHandled(FALSE);
}
}
void HWNDMessageHandler::OnSize(UINT param, const gfx::Size& size) {
RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
ResetWindowRegion(false, true);
if (needs_scroll_styles_ && !in_size_loop_) {
ShowScrollBar(hwnd(), SB_BOTH, FALSE);
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&AddScrollStylesToWindow, hwnd()));
}
}
void HWNDMessageHandler::OnSysCommand(UINT notification_code,
const gfx::Point& point) {
if (!delegate_->ShouldHandleSystemCommands())
return;
static const int sc_mask = 0xFFF0;
if (fullscreen_handler_->fullscreen() &&
(((notification_code & sc_mask) == SC_SIZE) ||
((notification_code & sc_mask) == SC_MOVE) ||
((notification_code & sc_mask) == SC_MAXIMIZE)))
return;
if (delegate_->IsUsingCustomFrame()) {
if ((notification_code & sc_mask) == SC_MINIMIZE ||
(notification_code & sc_mask) == SC_MAXIMIZE ||
(notification_code & sc_mask) == SC_RESTORE) {
delegate_->ResetWindowControls();
} else if ((notification_code & sc_mask) == SC_MOVE ||
(notification_code & sc_mask) == SC_SIZE) {
if (!IsVisible()) {
SetWindowLong(hwnd(), GWL_STYLE,
GetWindowLong(hwnd(), GWL_STYLE) | WS_VISIBLE);
}
}
}
if ((notification_code & sc_mask) == SC_KEYMENU && point.x() == 0) {
int modifiers = ui::EF_NONE;
if (base::win::IsShiftPressed())
modifiers |= ui::EF_SHIFT_DOWN;
if (base::win::IsCtrlPressed())
modifiers |= ui::EF_CONTROL_DOWN;
ui::Accelerator accelerator(ui::KeyboardCodeForWindowsKeyCode(VK_MENU),
modifiers);
delegate_->HandleAccelerator(accelerator);
return;
}
if (!delegate_->HandleCommand(notification_code)) {
if ((notification_code & sc_mask) == SC_SIZE)
in_size_loop_ = true;
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
DefWindowProc(hwnd(), WM_SYSCOMMAND, notification_code,
MAKELPARAM(point.x(), point.y()));
if (!ref.get())
return;
in_size_loop_ = false;
}
}
void HWNDMessageHandler::OnThemeChanged() {
ui::NativeThemeWin::instance()->CloseHandles();
}
LRESULT HWNDMessageHandler::OnTouchEvent(UINT message,
WPARAM w_param,
LPARAM l_param) {
int num_points = LOWORD(w_param);
scoped_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]);
if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param),
num_points, input.get(),
sizeof(TOUCHINPUT))) {
int flags = ui::GetModifiersFromKeyState();
TouchEvents touch_events;
for (int i = 0; i < num_points; ++i) {
POINT point;
point.x = TOUCH_COORD_TO_PIXEL(input[i].x) /
gfx::win::GetUndocumentedDPITouchScale();
point.y = TOUCH_COORD_TO_PIXEL(input[i].y) /
gfx::win::GetUndocumentedDPITouchScale();
if (base::win::GetVersion() == base::win::VERSION_WIN7) {
LPARAM l_param_ht = MAKELPARAM(point.x, point.y);
LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht);
if (hittest != HTCLIENT)
return 0;
}
ScreenToClient(hwnd(), &point);
last_touch_message_time_ = ::GetMessageTime();
ui::EventType touch_event_type = ui::ET_UNKNOWN;
if (input[i].dwFlags & TOUCHEVENTF_DOWN) {
touch_ids_.insert(input[i].dwID);
touch_event_type = ui::ET_TOUCH_PRESSED;
touch_down_context_ = true;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::ResetTouchDownContext,
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kTouchDownContextResetTimeout));
} else if (input[i].dwFlags & TOUCHEVENTF_UP) {
touch_ids_.erase(input[i].dwID);
touch_event_type = ui::ET_TOUCH_RELEASED;
} else if (input[i].dwFlags & TOUCHEVENTF_MOVE) {
touch_event_type = ui::ET_TOUCH_MOVED;
}
if (touch_event_type != ui::ET_UNKNOWN) {
base::TimeTicks now;
if (base::TimeTicks::IsHighResNowFastAndReliable())
now = base::TimeTicks::HighResNow();
else
now = base::TimeTicks::Now();
ui::TouchEvent event(touch_event_type,
gfx::Point(point.x, point.y),
id_generator_.GetGeneratedID(input[i].dwID),
now - base::TimeTicks());
event.set_flags(flags);
event.latency()->AddLatencyNumberWithTimestamp(
ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
0,
0,
base::TimeTicks::FromInternalValue(
event.time_stamp().ToInternalValue()),
1);
touch_events.push_back(event);
if (touch_event_type == ui::ET_TOUCH_RELEASED)
id_generator_.ReleaseNumber(input[i].dwID);
}
}
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::HandleTouchEvents,
weak_factory_.GetWeakPtr(), touch_events));
}
CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param));
SetMsgHandled(FALSE);
return 0;
}
void HWNDMessageHandler::OnWindowPosChanging(WINDOWPOS* window_pos) {
if (ignore_window_pos_changes_) {
if (!(window_pos->flags & ((IsVisible() ? SWP_HIDEWINDOW : SWP_SHOWWINDOW) |
SWP_FRAMECHANGED)) &&
(window_pos->flags & (SWP_NOZORDER | SWP_NOACTIVATE))) {
window_pos->flags |= SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW;
window_pos->flags &= ~(SWP_SHOWWINDOW | SWP_HIDEWINDOW);
}
} else if (!GetParent(hwnd())) {
RECT window_rect;
HMONITOR monitor;
gfx::Rect monitor_rect, work_area;
if (GetWindowRect(hwnd(), &window_rect) &&
GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) {
bool work_area_changed = (monitor_rect == last_monitor_rect_) &&
(work_area != last_work_area_);
if (monitor && (monitor == last_monitor_) &&
((fullscreen_handler_->fullscreen() &&
!fullscreen_handler_->metro_snap()) ||
work_area_changed)) {
gfx::Rect new_window_rect;
if (fullscreen_handler_->fullscreen()) {
new_window_rect = monitor_rect;
} else if (IsMaximized()) {
new_window_rect = work_area;
int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
new_window_rect.Inset(-border_thickness, -border_thickness);
} else {
new_window_rect = gfx::Rect(window_rect);
new_window_rect.AdjustToFit(work_area);
}
window_pos->x = new_window_rect.x();
window_pos->y = new_window_rect.y();
window_pos->cx = new_window_rect.width();
window_pos->cy = new_window_rect.height();
window_pos->flags &= ~(SWP_NOSIZE | SWP_NOMOVE | SWP_NOREDRAW);
window_pos->flags |= SWP_NOCOPYBITS;
ignore_window_pos_changes_ = true;
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&HWNDMessageHandler::StopIgnoringPosChanges,
weak_factory_.GetWeakPtr()));
}
last_monitor_ = monitor;
last_monitor_rect_ = monitor_rect;
last_work_area_ = work_area;
}
}
if (ScopedFullscreenVisibility::IsHiddenForFullscreen(hwnd())) {
window_pos->flags &= ~SWP_SHOWWINDOW;
}
if (window_pos->flags & SWP_SHOWWINDOW)
delegate_->HandleVisibilityChanging(true);
else if (window_pos->flags & SWP_HIDEWINDOW)
delegate_->HandleVisibilityChanging(false);
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::OnWindowPosChanged(WINDOWPOS* window_pos) {
if (DidClientAreaSizeChange(window_pos))
ClientAreaSizeChanged();
if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED &&
ui::win::IsAeroGlassEnabled() &&
(window_ex_style() & WS_EX_COMPOSITED) == 0) {
MARGINS m = {10, 10, 10, 10};
DwmExtendFrameIntoClientArea(hwnd(), &m);
}
if (window_pos->flags & SWP_SHOWWINDOW)
delegate_->HandleVisibilityChanged(true);
else if (window_pos->flags & SWP_HIDEWINDOW)
delegate_->HandleVisibilityChanged(false);
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::HandleTouchEvents(const TouchEvents& touch_events) {
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
for (size_t i = 0; i < touch_events.size() && ref; ++i)
delegate_->HandleTouchEvent(touch_events[i]);
}
void HWNDMessageHandler::ResetTouchDownContext() {
touch_down_context_ = false;
}
LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
WPARAM w_param,
LPARAM l_param,
bool track_mouse) {
if (!touch_ids_.empty())
return 0;
if (ui::IsMouseEventFromTouch(message)) {
LPARAM l_param_ht = l_param;
if (message != WM_MOUSEWHEEL && message != WM_MOUSEHWHEEL) {
POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param_ht);
MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1);
l_param_ht = MAKELPARAM(screen_point.x, screen_point.y);
}
LRESULT hittest = SendMessage(hwnd(), WM_NCHITTEST, 0, l_param_ht);
if (hittest == HTCLIENT || hittest == HTNOWHERE)
return 0;
}
if (message == WM_RBUTTONUP && is_right_mouse_pressed_on_caption_) {
is_right_mouse_pressed_on_caption_ = false;
ReleaseCapture();
POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param);
MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1);
w_param = SendMessage(hwnd(), WM_NCHITTEST, 0,
MAKELPARAM(screen_point.x, screen_point.y));
if (w_param == HTCAPTION || w_param == HTSYSMENU) {
gfx::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point));
return 0;
}
} else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) {
switch (w_param) {
case HTCLOSE:
case HTMINBUTTON:
case HTMAXBUTTON: {
w_param |= base::win::IsCtrlPressed() ? MK_CONTROL : 0;
w_param |= base::win::IsShiftPressed() ? MK_SHIFT : 0;
}
}
} else if (message == WM_NCRBUTTONDOWN &&
(w_param == HTCAPTION || w_param == HTSYSMENU)) {
is_right_mouse_pressed_on_caption_ = true;
SetCapture();
}
long message_time = GetMessageTime();
MSG msg = { hwnd(), message, w_param, l_param, message_time,
{ CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param) } };
ui::MouseEvent event(msg);
if (IsSynthesizedMouseMessage(message, message_time, l_param))
event.set_flags(event.flags() | ui::EF_FROM_TOUCH);
if (!(event.flags() & ui::EF_IS_NON_CLIENT))
delegate_->HandleTooltipMouseMove(message, w_param, l_param);
if (event.type() == ui::ET_MOUSE_MOVED && !HasCapture() && track_mouse) {
TrackMouseEvents((message == WM_NCMOUSEMOVE) ?
TME_NONCLIENT | TME_LEAVE : TME_LEAVE);
} else if (event.type() == ui::ET_MOUSE_EXITED) {
active_mouse_tracking_flags_ = 0;
} else if (event.type() == ui::ET_MOUSEWHEEL) {
return (ui::RerouteMouseWheel(hwnd(), w_param, l_param) ||
delegate_->HandleMouseEvent(ui::MouseWheelEvent(msg))) ? 0 : 1;
}
base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr());
bool handled = delegate_->HandleMouseEvent(event);
if (!ref.get())
return 0;
if (!handled && message == WM_NCLBUTTONDOWN && w_param != HTSYSMENU &&
delegate_->IsUsingCustomFrame()) {
DefWindowProcWithRedrawLock(message, w_param, l_param);
handled = true;
}
if (ref.get())
SetMsgHandled(handled);
return 0;
}
bool HWNDMessageHandler::IsSynthesizedMouseMessage(unsigned int message,
int message_time,
LPARAM l_param) {
if (ui::IsMouseEventFromTouch(message))
return true;
if (last_touch_message_time_ && message_time >= last_touch_message_time_ &&
((message_time - last_touch_message_time_) <=
kSynthesizedMouseTouchMessagesTimeDifference)) {
POINT mouse_location = CR_POINT_INITIALIZER_FROM_LPARAM(l_param);
::ClientToScreen(hwnd(), &mouse_location);
POINT cursor_pos = {0};
::GetCursorPos(&cursor_pos);
if (memcmp(&cursor_pos, &mouse_location, sizeof(POINT)))
return false;
return true;
}
return false;
}
}