This source file includes following definitions.
- Create
- UpdateParent
- GetParent
- OnManagerDeleted
- Show
- Hide
- SetBounds
- OnFinalMessage
- mouse_tracking_enabled_
- Init
- GetWindowEventTarget
- OnEraseBkGnd
- OnGetObject
- OnKeyboardRange
- OnMouseRange
- OnMouseLeave
- OnMouseActivate
- OnTouch
- OnScroll
- OnNCHitTest
- OnNCPaint
- OnPaint
- OnSetCursor
- OnNCCalcSize
- OnSize
#include "content/browser/renderer_host/legacy_render_widget_host_win.h"
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/win/windows_version.h"
#include "content/browser/accessibility/browser_accessibility_manager_win.h"
#include "content/browser/accessibility/browser_accessibility_win.h"
#include "content/public/common/content_switches.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/window_event_target.h"
#include "ui/gfx/geometry/rect.h"
namespace content {
LegacyRenderWidgetHostHWND::~LegacyRenderWidgetHostHWND() {
::DestroyWindow(hwnd());
}
scoped_ptr<LegacyRenderWidgetHostHWND> LegacyRenderWidgetHostHWND::Create(
HWND parent) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableLegacyIntermediateWindow) ||
(!GetWindowEventTarget(parent) && parent != ::GetDesktopWindow()))
return scoped_ptr<LegacyRenderWidgetHostHWND>();
scoped_ptr<LegacyRenderWidgetHostHWND> legacy_window_instance;
legacy_window_instance.reset(new LegacyRenderWidgetHostHWND(parent));
if (!::IsWindow(legacy_window_instance->hwnd()))
return scoped_ptr<LegacyRenderWidgetHostHWND>();
legacy_window_instance->Init();
return legacy_window_instance.Pass();
}
void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
::SetParent(hwnd(), parent);
if (parent == ::GetDesktopWindow()) {
::EnableWindow(hwnd(), FALSE);
} else {
::EnableWindow(hwnd(), TRUE);
}
}
HWND LegacyRenderWidgetHostHWND::GetParent() {
return ::GetParent(hwnd());
}
void LegacyRenderWidgetHostHWND::OnManagerDeleted() {
manager_ = NULL;
}
void LegacyRenderWidgetHostHWND::Show() {
::ShowWindow(hwnd(), SW_SHOW);
}
void LegacyRenderWidgetHostHWND::Hide() {
::ShowWindow(hwnd(), SW_HIDE);
}
void LegacyRenderWidgetHostHWND::SetBounds(const gfx::Rect& bounds) {
::SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(),
bounds.height(), 0);
}
void LegacyRenderWidgetHostHWND::OnFinalMessage(HWND hwnd) {
if (manager_)
manager_->OnAccessibleHwndDeleted();
}
LegacyRenderWidgetHostHWND::LegacyRenderWidgetHostHWND(HWND parent)
: manager_(NULL),
mouse_tracking_enabled_(false) {
RECT rect = {0};
Base::Create(parent, rect, L"Chrome Legacy Window",
WS_CHILDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
WS_EX_TRANSPARENT);
}
bool LegacyRenderWidgetHostHWND::Init() {
if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
ui::AreTouchEventsEnabled())
RegisterTouchWindow(hwnd(), TWF_WANTPALM);
HRESULT hr = ::CreateStdAccessibleObject(
hwnd(), OBJID_WINDOW, IID_IAccessible,
reinterpret_cast<void **>(window_accessible_.Receive()));
DCHECK(SUCCEEDED(hr));
return !!SUCCEEDED(hr);
}
ui::WindowEventTarget* LegacyRenderWidgetHostHWND::GetWindowEventTarget(
HWND parent) {
return reinterpret_cast<ui::WindowEventTarget*>(ui::ViewProp::GetValue(
parent, ui::WindowEventTarget::kWin32InputEventTarget));
}
LRESULT LegacyRenderWidgetHostHWND::OnEraseBkGnd(UINT message,
WPARAM w_param,
LPARAM l_param) {
return 1;
}
LRESULT LegacyRenderWidgetHostHWND::OnGetObject(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (OBJID_CLIENT != l_param || !manager_)
return static_cast<LRESULT>(0L);
base::win::ScopedComPtr<IAccessible> root(
manager_->GetRoot()->ToBrowserAccessibilityWin());
return LresultFromObject(IID_IAccessible, w_param,
static_cast<IAccessible*>(root.Detach()));
}
LRESULT LegacyRenderWidgetHostHWND::OnKeyboardRange(UINT message,
WPARAM w_param,
LPARAM l_param,
BOOL& handled) {
if (GetWindowEventTarget(GetParent())) {
return GetWindowEventTarget(GetParent())->HandleKeyboardMessage(
message, w_param, l_param);
}
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnMouseRange(UINT message,
WPARAM w_param,
LPARAM l_param,
BOOL& handled) {
if (message == WM_MOUSEMOVE) {
if (!mouse_tracking_enabled_) {
mouse_tracking_enabled_ = true;
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd();
tme.dwHoverTime = 0;
TrackMouseEvent(&tme);
}
}
if ((message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) &&
(message != WM_MOUSEWHEEL && message != WM_MOUSEHWHEEL)) {
POINT mouse_coords;
mouse_coords.x = GET_X_LPARAM(l_param);
mouse_coords.y = GET_Y_LPARAM(l_param);
::MapWindowPoints(hwnd(), GetParent(), &mouse_coords, 1);
l_param = MAKELPARAM(mouse_coords.x, mouse_coords.y);
}
if (GetWindowEventTarget(GetParent())) {
return GetWindowEventTarget(GetParent())->HandleMouseMessage(
message, w_param, l_param);
}
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnMouseLeave(UINT message,
WPARAM w_param,
LPARAM l_param) {
mouse_tracking_enabled_ = false;
if ((::GetCapture() != GetParent()) && GetWindowEventTarget(GetParent())) {
POINT cursor_pos;
::GetCursorPos(&cursor_pos);
if (::WindowFromPoint(cursor_pos) != GetParent()) {
return GetWindowEventTarget(GetParent())->HandleMouseMessage(
message, w_param, l_param);
}
}
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnMouseActivate(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (::GetWindowLong(GetParent(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)
return MA_NOACTIVATE;
if (::GetProp(hwnd(), ui::kIgnoreTouchMouseActivateForWindow)) {
::RemoveProp(hwnd(), ui::kIgnoreTouchMouseActivateForWindow);
return MA_NOACTIVATE;
}
return MA_ACTIVATE;
}
LRESULT LegacyRenderWidgetHostHWND::OnTouch(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (GetWindowEventTarget(GetParent())) {
return GetWindowEventTarget(GetParent())->HandleTouchMessage(
message, w_param, l_param);
}
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnScroll(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (GetWindowEventTarget(GetParent())) {
return GetWindowEventTarget(GetParent())->HandleScrollMessage(
message, w_param, l_param);
}
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnNCHitTest(UINT message,
WPARAM w_param,
LPARAM l_param) {
if (GetWindowEventTarget(GetParent())) {
LRESULT hit_test = GetWindowEventTarget(
GetParent())->HandleNcHitTestMessage(message, w_param, l_param);
if (hit_test == HTNOWHERE)
hit_test = HTCLIENT;
return hit_test;
}
return HTNOWHERE;
}
LRESULT LegacyRenderWidgetHostHWND::OnNCPaint(UINT message,
WPARAM w_param,
LPARAM l_param) {
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnPaint(UINT message,
WPARAM w_param,
LPARAM l_param) {
PAINTSTRUCT ps = {0};
::BeginPaint(hwnd(), &ps);
::EndPaint(hwnd(), &ps);
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnSetCursor(UINT message,
WPARAM w_param,
LPARAM l_param) {
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnNCCalcSize(UINT message,
WPARAM w_param,
LPARAM l_param) {
return 0;
}
LRESULT LegacyRenderWidgetHostHWND::OnSize(UINT message,
WPARAM w_param,
LPARAM l_param) {
long current_style = ::GetWindowLong(hwnd(), GWL_STYLE);
::SetWindowLong(hwnd(), GWL_STYLE,
current_style | WS_VSCROLL | WS_HSCROLL);
return 0;
}