diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 23:52:50 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 23:52:50 +0000 |
commit | 5f05625cfd9470302e38206b6583bcb7e6f256f4 (patch) | |
tree | d553fd9e4f79fff38849d4eaf6d83384c5f51356 | |
parent | 4c7222f403bd230376ad7eb2b95dce8232b21336 (diff) | |
download | chromium_src-5f05625cfd9470302e38206b6583bcb7e6f256f4.zip chromium_src-5f05625cfd9470302e38206b6583bcb7e6f256f4.tar.gz chromium_src-5f05625cfd9470302e38206b6583bcb7e6f256f4.tar.bz2 |
Remove NativeWidgetWin/WidgetImpl again. I'm going to take a different approach to extracting this stuff.
BUG=72040
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/6574043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75995 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/views.gyp | 11 | ||||
-rw-r--r-- | views/widget/native_widget.h | 83 | ||||
-rw-r--r-- | views/widget/native_widget_listener.h | 61 | ||||
-rw-r--r-- | views/widget/native_widget_win.cc | 671 | ||||
-rw-r--r-- | views/widget/native_widget_win.h | 281 | ||||
-rw-r--r-- | views/widget/native_widget_win_unittest.cc | 90 | ||||
-rw-r--r-- | views/widget/widget_impl.cc | 456 | ||||
-rw-r--r-- | views/widget/widget_impl.h | 203 | ||||
-rw-r--r-- | views/widget/widget_impl_test_util.cc | 34 | ||||
-rw-r--r-- | views/widget/widget_impl_test_util.h | 22 | ||||
-rw-r--r-- | views/widget/widget_impl_unittest.cc | 38 |
11 files changed, 0 insertions, 1950 deletions
diff --git a/views/views.gyp b/views/views.gyp index b729203..b97d617 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -346,17 +346,9 @@ 'widget/tooltip_window_gtk.h', 'widget/monitor_win.cc', 'widget/monitor_win.h', - 'widget/native_widget.h', - 'widget/native_widget_listener.h', - 'widget/native_widget_win.cc', - 'widget/native_widget_win.h', - 'widget/widget_impl.cc', - 'widget/widget_impl.h', 'widget/widget.h', 'widget/widget_gtk.cc', 'widget/widget_gtk.h', - 'widget/widget_impl.cc', - 'widget/widget_impl.h', 'widget/widget_utils.cc', 'widget/widget_utils.h', 'widget/widget_win.cc', @@ -494,9 +486,6 @@ 'run_all_unittests.cc', 'test/test_views_delegate.h', 'view_unittest.cc', - 'widget/native_widget_win_unittest.cc', - 'widget/widget_impl_test_util.cc', - 'widget/widget_impl_test_util.h', 'widget/widget_win_unittest.cc', 'window/window_win_unittest.cc', diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h deleted file mode 100644 index 4b594e0..0000000 --- a/views/widget/native_widget.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_WIDGET_NATIVE_WIDGET_H_ -#define VIEWS_WIDGET_NATIVE_WIDGET_H_ - -#include "views/native_types.h" - -namespace gfx{ -class Path; -class Rect; -} - -namespace ui { -class OSExchangeData; -} - -namespace views { -namespace internal { -class NativeWidgetListener; -} -class View; -class WidgetImpl; - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidget interface -// -// An interface implemented by an object that encapsulates rendering, event -// handling and widget management provided by an underlying native toolkit. -// -class NativeWidget { - public: - virtual ~NativeWidget() {} - - static NativeWidget* CreateNativeWidget( - internal::NativeWidgetListener* listener); - - // Retrieves the NativeWidget implementation associated with the given - // NativeView or Window, or NULL if the supplied handle has no associated - // NativeView. - static NativeWidget* GetNativeWidgetForNativeView( - gfx::NativeView native_view); - static NativeWidget* GetNativeWidgetForNativeWindow( - gfx::NativeWindow native_window); - - // Retrieves the top NativeWidget in the hierarchy containing the given - // NativeView, or NULL if there is no NativeWidget that contains it. - static NativeWidget* GetTopLevelNativeWidget(gfx::NativeView native_view); - - // See WidgetImpl for documentation and notes. - virtual void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) = 0; - virtual void SetNativeWindowProperty(const char* name, void* value) = 0; - virtual void* GetNativeWindowProperty(const char* name) const = 0; - virtual gfx::Rect GetWindowScreenBounds() const = 0; - virtual gfx::Rect GetClientAreaScreenBounds() const = 0; - virtual void SetBounds(const gfx::Rect& bounds) = 0; - virtual void SetShape(const gfx::Path& shape) = 0; - virtual gfx::NativeView GetNativeView() const = 0; - virtual void Show() = 0; - virtual void Hide() = 0; - virtual void Close() = 0; - virtual void MoveAbove(NativeWidget* other) = 0; - virtual void SetAlwaysOnTop(bool always_on_top) = 0; - virtual bool IsVisible() const = 0; - virtual bool IsActive() const = 0; - virtual void SetMouseCapture() = 0; - virtual void ReleaseMouseCapture() = 0; - virtual bool HasMouseCapture() const = 0; - virtual bool ShouldReleaseCaptureOnMouseReleased() const = 0; - virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0; - virtual void FocusNativeView(gfx::NativeView native_view) = 0; - virtual void RunShellDrag(const ui::OSExchangeData& data, int operation) = 0; - virtual void SetCursor(gfx::NativeCursor cursor) = 0; - virtual WidgetImpl* GetWidgetImpl() = 0; - virtual const WidgetImpl* GetWidgetImpl() const = 0; -}; - -} // namespace views - -#endif // VIEWS_WIDGET_NATIVE_WIDGET_H_ - diff --git a/views/widget/native_widget_listener.h b/views/widget/native_widget_listener.h deleted file mode 100644 index d9f524d..0000000 --- a/views/widget/native_widget_listener.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ -#define VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ - -namespace gfx { -class Canvas; -class Point; -class Size; -} - -namespace views { -class KeyEvent; -class MouseEvent; -class MouseWheelEvent; -class WidgetImpl; - -namespace internal { - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetListener interface -// -// An interface implemented by the Widget that handles events sent from a -// NativeWidget implementation. -// -class NativeWidgetListener { - public: - virtual ~NativeWidgetListener() {} - - virtual void OnClose() = 0; - - virtual void OnDestroy() = 0; - virtual void OnDisplayChanged() = 0; - - virtual bool OnKeyEvent(const KeyEvent& event) = 0; - - virtual void OnMouseCaptureLost() = 0; - - virtual bool OnMouseEvent(const MouseEvent& event) = 0; - virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) = 0; - - virtual void OnNativeWidgetCreated() = 0; - - virtual void OnPaint(gfx::Canvas* canvas) = 0; - virtual void OnSizeChanged(const gfx::Size& size) = 0; - - virtual void OnNativeFocus(gfx::NativeView focused_view) = 0; - virtual void OnNativeBlur(gfx::NativeView focused_view) = 0; - - virtual void OnWorkAreaChanged() = 0; - - virtual WidgetImpl* GetWidgetImpl() = 0; - virtual const WidgetImpl* GetWidgetImpl() const = 0; -}; - -} // namespace internal -} // namespace views - -#endif // VIEWS_WIDGET_NATIVE_WIDGET_LISTENER_H_ diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc deleted file mode 100644 index 32e0310..0000000 --- a/views/widget/native_widget_win.cc +++ /dev/null @@ -1,671 +0,0 @@ -// Copyright (c) 2011 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 "views/widget/native_widget_win.h" - -#include "base/scoped_ptr.h" -#include "ui/base/dragdrop/drag_drop_types.h" -#include "ui/base/dragdrop/drag_source.h" -#include "ui/base/dragdrop/os_exchange_data.h" -#include "ui/base/dragdrop/os_exchange_data_provider_win.h" -#include "ui/base/system_monitor/system_monitor.h" -#include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/gfx/canvas_skia.h" -#include "ui/gfx/native_theme_win.h" -#include "ui/gfx/path.h" -#include "views/view.h" -#include "views/widget/widget_impl.h" - -namespace views { -namespace internal { - -namespace { - -// Links the HWND to its Widget. -const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; - -// A custom MSAA object id used to determine if a screen reader is actively -// listening for MSAA events. -const int kMSAAObjectID = 1; - -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, public: - -NativeWidgetWin::NativeWidgetWin(NativeWidgetListener* listener) - : listener_(listener), - active_mouse_tracking_flags_(0), - has_capture_(false), - previous_cursor_(NULL) { -} - -NativeWidgetWin::~NativeWidgetWin() { -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, NativeWidget implementation: - -void NativeWidgetWin::InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) { - WindowImpl::Init(parent, bounds); -} - -void NativeWidgetWin::SetNativeWindowProperty(const char* name, void* value) { - // Remove the existing property (if any). - for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { - if ((*i)->Key() == name) { - props_.erase(i); - break; - } - } - - if (value) - props_.push_back(new ui::ViewProp(hwnd(), name, value)); -} - -void* NativeWidgetWin::GetNativeWindowProperty(const char* name) const { - return ui::ViewProp::GetValue(hwnd(), name); -} - -gfx::Rect NativeWidgetWin::GetWindowScreenBounds() const { - RECT r; - GetWindowRect(hwnd(), &r); - return gfx::Rect(r); -} - -gfx::Rect NativeWidgetWin::GetClientAreaScreenBounds() 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); -} - -void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { - SetWindowPos(hwnd(), NULL, bounds.x(), bounds.y(), bounds.width(), - bounds.height(), SWP_NOACTIVATE | SWP_NOZORDER); -} - -void NativeWidgetWin::SetShape(const gfx::Path& shape) { - SetWindowRgn(hwnd(), shape.CreateNativeRegion(), TRUE); -} - -gfx::NativeView NativeWidgetWin::GetNativeView() const { - return hwnd(); -} - -void NativeWidgetWin::Show() { - if (IsWindow(hwnd())) - ShowWindow(hwnd(), SW_SHOWNOACTIVATE); - // TODO(beng): move to windowposchanging to trap visibility changes instead. - if (IsLayeredWindow()) - SchedulePaint(); -} - -void NativeWidgetWin::Hide() { - if (IsWindow(hwnd())) { - // NOTE: Be careful not to activate any windows here (for example, calling - // ShowWindow(SW_HIDE) will automatically activate another window). This - // code can be called while a window is being deactivated, and activating - // another window will screw up the activation that is already in progress. - SetWindowPos(hwnd(), NULL, 0, 0, 0, 0, - SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | - SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); - } -} - -void NativeWidgetWin::Close() { - DestroyWindow(hwnd()); -} - -void NativeWidgetWin::MoveAbove(NativeWidget* other) { - SetWindowPos(hwnd(), other->GetNativeView(), 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); -} - -void NativeWidgetWin::SetAlwaysOnTop(bool always_on_top) { - DWORD style = always_on_top ? window_ex_style() | WS_EX_TOPMOST - : window_ex_style() & ~WS_EX_TOPMOST; - set_window_ex_style(style); - SetWindowLong(hwnd(), GWL_EXSTYLE, window_ex_style()); -} - -bool NativeWidgetWin::IsVisible() const { - return !!IsWindowVisible(hwnd()); -} - -bool NativeWidgetWin::IsActive() const { - WINDOWINFO info; - return ::GetWindowInfo(hwnd(), &info) && - ((info.dwWindowStatus & WS_ACTIVECAPTION) != 0); -} - -void NativeWidgetWin::SetMouseCapture() { - SetCapture(hwnd()); - has_capture_ = true; -} - -void NativeWidgetWin::ReleaseMouseCapture() { - ReleaseCapture(); - has_capture_ = false; -} - -bool NativeWidgetWin::HasMouseCapture() const { - return has_capture_; -} - -bool NativeWidgetWin::ShouldReleaseCaptureOnMouseReleased() const { - return true; -} - -void NativeWidgetWin::SchedulePaintInRect(const gfx::Rect& rect) { - // InvalidateRect() expects client coordinates. - RECT r = rect.ToRECT(); - ::InvalidateRect(hwnd(), &r, FALSE); -} - -void NativeWidgetWin::FocusNativeView(gfx::NativeView native_view) { - if (IsWindow(native_view)) { - if (GetFocus() != native_view) - SetFocus(native_view); - } else { - // NULL or invalid |native_view| passed, we consider this to be clearing - // focus. Keep the top level window focused so we continue to receive - // key events. - SetFocus(hwnd()); - } -} - -void NativeWidgetWin::RunShellDrag(const ui::OSExchangeData& data, - int operation) { - scoped_refptr<ui::DragSource> drag_source(new ui::DragSource); - DWORD effects; - DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), drag_source, - ui::DragDropTypes::DragOperationToDropEffect(operation), &effects); -} - -void NativeWidgetWin::SetCursor(gfx::NativeCursor cursor) { - if (cursor) { - previous_cursor_ = ::SetCursor(cursor); - } else if (previous_cursor_) { - ::SetCursor(previous_cursor_); - previous_cursor_ = NULL; - } -} - -WidgetImpl* NativeWidgetWin::GetWidgetImpl() { - return listener_->GetWidgetImpl(); -} - -const WidgetImpl* NativeWidgetWin::GetWidgetImpl() const { - return listener_->GetWidgetImpl(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidetWin, MessageLoopForUI::Observer implementation - -void NativeWidgetWin::WillProcessMessage(const MSG& msg) { -} - -void NativeWidgetWin::DidProcessMessage(const MSG& msg) { - RedrawInvalidRect(); -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, message handlers: - -void NativeWidgetWin::OnActivate(UINT action, BOOL minimized, HWND window) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnActivateApp(BOOL active, DWORD thread_id) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnAppCommand(HWND window, short app_command, - WORD device, int keystate) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnCancelMode() { -} - -void NativeWidgetWin::OnCaptureChanged(HWND hwnd) { - has_capture_ = false; - listener_->OnMouseCaptureLost(); -} - -void NativeWidgetWin::OnClose() { - listener_->OnClose(); -} - -void NativeWidgetWin::OnCommand(UINT notification_code, int command_id, - HWND window) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) { - SetNativeWindowProperty(kNativeWidgetKey, this); - listener_->OnNativeWidgetCreated(); - // 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); - return 0; -} - -void NativeWidgetWin::OnDestroy() { - // TODO(beng): drop_target_ - props_.reset(); -} - -void NativeWidgetWin::OnDisplayChange(UINT bits_per_pixel, CSize screen_size) { - listener_->OnDisplayChanged(); -} - -LRESULT NativeWidgetWin::OnDwmCompositionChanged(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnEnterSizeMove() { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) { - // This is needed for magical win32 flicker ju-ju - return 1; -} - -void NativeWidgetWin::OnExitMenuLoop(BOOL is_track_popup_menu) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnExitSizeMove() { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnGetObject(UINT message, WPARAM w_param, - LPARAM l_param) { - return static_cast<LRESULT>(0L); -} - -void NativeWidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnHScroll(int scroll_type, short position, - HWND scrollbar) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnInitMenu(HMENU menu) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnInitMenuPopup(HMENU menu, UINT position, - BOOL is_system_menu) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnKeyDown(UINT message, WPARAM w_param, - LPARAM l_param) { - MSG msg; - MakeMSG(&msg, message, w_param, l_param); - SetMsgHandled(listener_->OnKeyEvent(KeyEvent(msg))); - return 0; -} - -LRESULT NativeWidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { - MSG msg; - MakeMSG(&msg, message, w_param, l_param); - SetMsgHandled(listener_->OnKeyEvent(KeyEvent(msg))); - return 0; -} - -void NativeWidgetWin::OnKillFocus(HWND focused_window) { - listener_->OnNativeBlur(focused_window); - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnMouseActivate(HWND window, UINT hittest_code, - UINT message) { - SetMsgHandled(FALSE); - return MA_ACTIVATE; -} - -LRESULT NativeWidgetWin::OnMouseLeave(UINT message, WPARAM w_param, - LPARAM l_param) { - // TODO(beng): tooltip - MSG msg; - MakeMSG(&msg, message, w_param, l_param); - //SetMsgHandled(listener_->OnMouseEvent(MouseEvent(msg))); - - // Reset our tracking flag so that future mouse movement over this WidgetWin - // results in a new tracking session. - active_mouse_tracking_flags_ = 0; - - return 0; -} - -void NativeWidgetWin::OnMove(const CPoint& point) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnMoving(UINT param, LPRECT new_bounds) { -} - -LRESULT NativeWidgetWin::OnMouseRange(UINT message, WPARAM w_param, - LPARAM l_param) { - // TODO(beng): tooltips - ProcessMouseRange(message, w_param, l_param, false); - return 0; -} - -LRESULT NativeWidgetWin::OnNCActivate(BOOL active) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCHitTest(UINT message, WPARAM w_param, - LPARAM l_param) { - LRESULT lr = DefWindowProc(hwnd(), message, w_param, l_param); - return lr; -} - -LRESULT NativeWidgetWin::OnNCMouseRange(UINT message, WPARAM w_param, - LPARAM l_param) { - bool processed = ProcessMouseRange(message, w_param, l_param, true); - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnNCPaint(HRGN rgn) { - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnNCUAHDrawCaption(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNCUAHDrawFrame(UINT message, - WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnNotify(int w_param, NMHDR* l_param) { - // TODO(beng): tooltips - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnPaint(HDC dc) { - if (IsLayeredWindow()) { - // We need to clip to the dirty rect ourselves. - window_contents_->save(SkCanvas::kClip_SaveFlag); - RECT r; - GetUpdateRect(hwnd(), &r, FALSE); - window_contents_->ClipRectInt(r.left, r.top, r.right - r.left, - r.bottom - r.top); - listener_->OnPaint(window_contents_.get()); - window_contents_->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 = window_contents_->getTopPlatformDevice().getBitmapDC(); - POINT zero = {0, 0}; - BLENDFUNCTION blend = {AC_SRC_OVER, 0, 125, AC_SRC_ALPHA}; - UpdateLayeredWindow(hwnd(), NULL, &position, &size, dib_dc, &zero, - RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA); - } else { - scoped_ptr<gfx::CanvasPaint> canvas( - gfx::CanvasPaint::CreateCanvasPaint(hwnd())); - listener_->OnPaint(canvas->AsCanvas()); - } -} - -LRESULT NativeWidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { - ui::SystemMonitor* monitor = ui::SystemMonitor::Get(); - if (monitor) - monitor->ProcessWmPowerBroadcastMessage(power_event); - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnReflectedMessage(UINT message, WPARAM w_param, - LPARAM l_param) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnSetFocus(HWND focused_window) { - listener_->OnNativeFocus(focused_window); - SetMsgHandled(FALSE); -} - -LRESULT NativeWidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { - SetMsgHandled(FALSE); - return 0; -} - -LRESULT NativeWidgetWin::OnSetText(const wchar_t* text) { - SetMsgHandled(FALSE); - return 0; -} - -void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { - if (flags == SPI_SETWORKAREA) - listener_->OnWorkAreaChanged(); - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnSize(UINT param, const CSize& size) { - gfx::Size s(size.cx, size.cy); - listener_->OnSizeChanged(s); - if (IsLayeredWindow()) { - window_contents_.reset( - new gfx::CanvasSkia(s.width(), s.height(), false)); - } -} - -void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnThemeChanged() { - gfx::NativeTheme::instance()->CloseHandles(); -} - -void NativeWidgetWin::OnVScroll(int scroll_type, short position, - HWND scrollbar) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnWindowPosChanging(WINDOWPOS* window_pos) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) { - SetMsgHandled(FALSE); -} - -void NativeWidgetWin::OnFinalMessage(HWND window) { - delete this; -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, WindowImpl overrides: - -HICON NativeWidgetWin::GetDefaultWindowIcon() const { - return NULL; -} - -LRESULT NativeWidgetWin::OnWndProc(UINT message, WPARAM w_param, - LPARAM l_param) { - LRESULT result = 0; - - // Otherwise we handle everything else. - if (!ProcessWindowMessage(hwnd(), message, w_param, l_param, result)) - result = DefWindowProc(hwnd(), message, w_param, l_param); - if (message == WM_NCDESTROY) { - MessageLoopForUI::current()->RemoveObserver(this); - OnFinalMessage(hwnd()); - } - return result; -} - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin, private: - -void NativeWidgetWin::TrackMouseEvents(DWORD mouse_tracking_flags) { - // Begin tracking mouse events for this HWND so that we get WM_MOUSELEAVE - // when the user moves the mouse outside this HWND's bounds. - if (active_mouse_tracking_flags_ == 0 || mouse_tracking_flags & TME_CANCEL) { - if (mouse_tracking_flags & TME_CANCEL) { - // We're about to cancel active mouse tracking, so empty out the stored - // state. - 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); - } -} - -bool NativeWidgetWin::ProcessMouseRange(UINT message, WPARAM w_param, - LPARAM l_param, bool non_client) { - MSG msg; - MakeMSG(&msg, message, w_param, l_param); - if (message == WM_MOUSEWHEEL) { - // Reroute the mouse-wheel to the window under the mouse pointer if - // applicable. - // TODO(beng): - //if (views::RerouteMouseWheel(hwnd(), w_param, l_param)) - // return 0; - //return listener_->OnMouseWheelEvent(MouseWheelEvent(msg)); - return 0; - } - // Windows only fires WM_MOUSELEAVE events if the application begins - // "tracking" mouse events for a given HWND during WM_MOUSEMOVE events. - // We need to call |TrackMouseEvents| to listen for WM_MOUSELEAVE. - if (!has_capture_) - TrackMouseEvents(non_client ? TME_NONCLIENT | TME_LEAVE : TME_LEAVE); - //return listener_->OnMouseEvent(MouseEvent(msg)); - return 0; -} - -void NativeWidgetWin::MakeMSG(MSG* msg, UINT message, WPARAM w_param, - LPARAM l_param) const { - msg->hwnd = hwnd(); - msg->message = message; - msg->wParam = w_param; - msg->lParam = l_param; - msg->time = 0; - msg->pt.x = msg->pt.y = 0; -} - -void NativeWidgetWin::CloseNow() { - DestroyWindow(hwnd()); -} - -void NativeWidgetWin::SchedulePaint() { - ::InvalidateRect(hwnd(), NULL, FALSE); -} - -void NativeWidgetWin::RedrawInvalidRect() { - RECT r; - if (GetUpdateRect(hwnd(), &r, FALSE)) { - RedrawWindow(hwnd(), &r, NULL, - RDW_INVALIDATE | RDW_UPDATENOW | RDW_NOCHILDREN); - } -} - -bool NativeWidgetWin::IsLayeredWindow() const { - return !!(window_ex_style() & WS_EX_LAYERED); -} - -} // namespace internal - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidget, public: - -// static -NativeWidget* NativeWidget::CreateNativeWidget( - internal::NativeWidgetListener* listener) { - return new internal::NativeWidgetWin(listener); -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeView( - gfx::NativeView native_view) { - if (!ui::WindowImpl::IsWindowImpl(native_view)) - return NULL; - return reinterpret_cast<internal::NativeWidgetWin*>( - ui::ViewProp::GetValue(native_view, internal::kNativeWidgetKey)); -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow( - gfx::NativeWindow native_window) { - return GetNativeWidgetForNativeView(native_window); -} - -// static -NativeWidget* NativeWidget::GetTopLevelNativeWidget( - gfx::NativeView native_view) { - // First, check if the top-level window is a Widget. - HWND root = ::GetAncestor(native_view, GA_ROOT); - if (!root) - return NULL; - - NativeWidget* widget = GetNativeWidgetForNativeView(root); - if (widget) - return widget; - - // Second, try to locate the last Widget window in the parent hierarchy. - HWND parent_hwnd = native_view; - NativeWidget* parent_widget; - do { - parent_widget = GetNativeWidgetForNativeView(parent_hwnd); - if (parent_widget) { - widget = parent_widget; - parent_hwnd = ::GetAncestor(parent_hwnd, GA_PARENT); - } - } while (parent_hwnd != NULL && parent_widget != NULL); - - return widget; -} - -} // namespace views diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h deleted file mode 100644 index 17f460b..0000000 --- a/views/widget/native_widget_win.h +++ /dev/null @@ -1,281 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ -#define VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ - -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "base/scoped_vector.h" -#include "ui/base/win/window_impl.h" -#include "views/widget/native_widget.h" - -namespace gfx { -class CanvasSkia; -} - -namespace ui { -class ViewProp; -} - -namespace views { -class WidgetImpl; - -namespace internal { - -// A Windows message reflected from other windows. This message is sent with the -// following arguments: -// HWND - Target window -// MSG - kReflectedMessage -// WPARAM - Should be 0 -// LPARAM - Pointer to MSG struct containing the original message. -const int kReflectedMessage = WM_APP + 3; - -// These two messages aren't defined in winuser.h, but they are sent to windows -// with captions. They appear to paint the window caption and frame. -// Unfortunately if you override the standard non-client rendering as we do -// with CustomFrameWindow, sometimes Windows (not deterministically -// reproducibly but definitely frequently) will send these messages to the -// window and paint the standard caption/title over the top of the custom one. -// So we need to handle these messages in CustomFrameWindow to prevent this -// from happening. -const int WM_NCUAHDRAWCAPTION = 0xAE; -const int WM_NCUAHDRAWFRAME = 0xAF; - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidgetWin class -// -// A NativeWidget implementation that wraps a Win32 HWND. -// -class NativeWidgetWin : public NativeWidget, - public ui::WindowImpl, - public MessageLoopForUI::Observer { - public: - explicit NativeWidgetWin(NativeWidgetListener* listener); - virtual ~NativeWidgetWin(); - - private: - typedef ScopedVector<ui::ViewProp> ViewProps; - - // Overridden from NativeWidget: - virtual void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds); - virtual void SetNativeWindowProperty(const char* name, void* value); - virtual void* GetNativeWindowProperty(const char* name) const; - virtual gfx::Rect GetWindowScreenBounds() const; - virtual gfx::Rect GetClientAreaScreenBounds() const; - virtual void SetBounds(const gfx::Rect& bounds); - virtual void SetShape(const gfx::Path& shape); - virtual gfx::NativeView GetNativeView() const; - virtual void Show(); - virtual void Hide(); - virtual void Close(); - virtual void MoveAbove(NativeWidget* other); - virtual void SetAlwaysOnTop(bool always_on_top); - virtual bool IsVisible() const; - virtual bool IsActive() const; - virtual void SetMouseCapture(); - virtual void ReleaseMouseCapture(); - virtual bool HasMouseCapture() const; - virtual bool ShouldReleaseCaptureOnMouseReleased() const; - virtual void SchedulePaintInRect(const gfx::Rect& rect); - virtual void FocusNativeView(gfx::NativeView native_view); - virtual void RunShellDrag(const ui::OSExchangeData& data, int operation); - virtual void SetCursor(gfx::NativeCursor cursor); - virtual WidgetImpl* GetWidgetImpl(); - virtual const WidgetImpl* GetWidgetImpl() const; - - // Overridden from MessageLoop::Observer: - void WillProcessMessage(const MSG& msg); - virtual void DidProcessMessage(const MSG& msg); - - // Message handlers - BEGIN_MSG_MAP_EX(NativeWidgetWin) - // Range handlers must go first! - MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) - MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCMBUTTONDBLCLK, OnNCMouseRange) - - // Reflected message handler - MESSAGE_HANDLER_EX(kReflectedMessage, OnReflectedMessage) - - // CustomFrameWindow hacks - MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption) - MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame) - - // Vista and newer - MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged) - - // Non-atlcrack.h handlers - MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject) - MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseLeave) - MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseLeave) - - // Key events. - MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyDown) - MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyUp) - MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyDown); - MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyUp); - - // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU. - MSG_WM_ACTIVATE(OnActivate) - MSG_WM_ACTIVATEAPP(OnActivateApp) - MSG_WM_APPCOMMAND(OnAppCommand) - MSG_WM_CANCELMODE(OnCancelMode) - MSG_WM_CAPTURECHANGED(OnCaptureChanged) - MSG_WM_CLOSE(OnClose) - MSG_WM_COMMAND(OnCommand) - MSG_WM_CREATE(OnCreate) - MSG_WM_DESTROY(OnDestroy) - MSG_WM_DISPLAYCHANGE(OnDisplayChange) - MSG_WM_ERASEBKGND(OnEraseBkgnd) - MSG_WM_ENDSESSION(OnEndSession) - MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove) - MSG_WM_EXITMENULOOP(OnExitMenuLoop) - MSG_WM_EXITSIZEMOVE(OnExitSizeMove) - MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo) - MSG_WM_HSCROLL(OnHScroll) - MSG_WM_INITMENU(OnInitMenu) - MSG_WM_INITMENUPOPUP(OnInitMenuPopup) - MSG_WM_KILLFOCUS(OnKillFocus) - MSG_WM_MOUSEACTIVATE(OnMouseActivate) - MSG_WM_MOVE(OnMove) - MSG_WM_MOVING(OnMoving) - MSG_WM_NCACTIVATE(OnNCActivate) - MSG_WM_NCCALCSIZE(OnNCCalcSize) - MESSAGE_HANDLER_EX(WM_NCHITTEST, OnNCHitTest) - MSG_WM_NCPAINT(OnNCPaint) - MSG_WM_NOTIFY(OnNotify) - MSG_WM_PAINT(OnPaint) - MSG_WM_POWERBROADCAST(OnPowerBroadcast) - MSG_WM_SETFOCUS(OnSetFocus) - MSG_WM_SETICON(OnSetIcon) - MSG_WM_SETTEXT(OnSetText) - MSG_WM_SETTINGCHANGE(OnSettingChange) - MSG_WM_SIZE(OnSize) - MSG_WM_SYSCOMMAND(OnSysCommand) - MSG_WM_THEMECHANGED(OnThemeChanged) - MSG_WM_VSCROLL(OnVScroll) - MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging) - MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged) - END_MSG_MAP() - - virtual void OnActivate(UINT action, BOOL minimized, HWND window); - virtual void OnActivateApp(BOOL active, DWORD thread_id); - virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, - int keystate); - virtual void OnCancelMode(); - virtual void OnCaptureChanged(HWND hwnd); - virtual void OnClose(); - virtual void OnCommand(UINT notification_code, int command_id, HWND window); - virtual LRESULT OnCreate(CREATESTRUCT* create_struct); - // WARNING: If you override this be sure and invoke super, otherwise we'll - // leak a few things. - virtual void OnDestroy(); - virtual void OnDisplayChange(UINT bits_per_pixel, CSize screen_size); - virtual LRESULT OnDwmCompositionChanged(UINT message, - WPARAM w_param, - LPARAM l_param); - virtual void OnEndSession(BOOL ending, UINT logoff); - virtual void OnEnterSizeMove(); - virtual LRESULT OnEraseBkgnd(HDC dc); - virtual void OnExitMenuLoop(BOOL is_track_popup_menu); - virtual void OnExitSizeMove(); - virtual LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info); - virtual void OnHScroll(int scroll_type, short position, HWND scrollbar); - virtual void OnInitMenu(HMENU menu); - virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu); - virtual LRESULT OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnKillFocus(HWND focused_window); - virtual LRESULT OnMouseActivate(HWND window, UINT hittest_code, UINT message); - virtual LRESULT OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnMove(const CPoint& point); - virtual void OnMoving(UINT param, LPRECT new_bounds); - virtual LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCActivate(BOOL active); - virtual LRESULT OnNCCalcSize(BOOL w_param, LPARAM l_param); - virtual LRESULT OnNCHitTest(UINT message, WPARAM w_param, LPARAM l_param); - virtual LRESULT OnNCMouseRange(UINT message, WPARAM w_param, LPARAM l_param); - virtual void OnNCPaint(HRGN rgn); - virtual LRESULT OnNCUAHDrawCaption(UINT message, - WPARAM w_param, - LPARAM l_param); - virtual LRESULT OnNCUAHDrawFrame(UINT message, WPARAM w_param, - LPARAM l_param); - virtual LRESULT OnNotify(int w_param, NMHDR* l_param); - virtual void OnPaint(HDC dc); - virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data); - virtual LRESULT OnReflectedMessage(UINT message, WPARAM w_param, - LPARAM l_param); - virtual void OnSetFocus(HWND focused_window); - virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); - virtual LRESULT OnSetText(const wchar_t* text); - virtual void OnSettingChange(UINT flags, const wchar_t* section); - virtual void OnSize(UINT param, const CSize& size); - virtual void OnSysCommand(UINT notification_code, CPoint click); - virtual void OnThemeChanged(); - virtual void OnVScroll(int scroll_type, short position, HWND scrollbar); - virtual void OnWindowPosChanging(WINDOWPOS* window_pos); - virtual void OnWindowPosChanged(WINDOWPOS* window_pos); - - // Deletes this window as it is destroyed, override to provide different - // behavior. - virtual void OnFinalMessage(HWND window); - - // Overridden from WindowImpl: - virtual HICON GetDefaultWindowIcon() const; - virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); - - // Start tracking all mouse events so that this window gets sent mouse leave - // messages too. - void TrackMouseEvents(DWORD mouse_tracking_flags); - - bool ProcessMouseRange(UINT message, WPARAM w_param, LPARAM l_param, - bool non_client); - void ProcessMouseMoved(const CPoint& point, UINT flags, bool is_nonclient); - void ProcessMouseExited(); - - // Fills out a MSG struct with the supplied values. - void MakeMSG(MSG* msg, UINT message, WPARAM w_param, LPARAM l_param) const; - - void CloseNow(); - - void SchedulePaint(); - void RedrawInvalidRect(); - - bool IsLayeredWindow() const; - - // A listener implementation that handles events received here. - NativeWidgetListener* listener_; - - // The flags currently being used with TrackMouseEvent to track mouse - // messages. 0 if there is no active tracking. The value of this member is - // used when tracking is canceled. - DWORD active_mouse_tracking_flags_; - - // True when the HWND has event capture. - bool has_capture_; - - // A canvas that contains the window contents in the case of a layered - // window. - scoped_ptr<gfx::CanvasSkia> window_contents_; - - // The last cursor that was active before the current one was selected. Saved - // so that we can restore it. - gfx::NativeCursor previous_cursor_; - - // Properties associated with this NativeWidget implementation. - // TODO(beng): move to WidgetImpl. - ViewProps props_; - - DISALLOW_COPY_AND_ASSIGN(NativeWidgetWin); -}; - -} // namespace internal -} // namespace views - -#endif // VIEWS_WIDGET_NATIVE_WIDGET_WIN_H_ - diff --git a/views/widget/native_widget_win_unittest.cc b/views/widget/native_widget_win_unittest.cc deleted file mode 100644 index b29d360..0000000 --- a/views/widget/native_widget_win_unittest.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" -#include "ui/base/win/window_impl.h" -#include "views/view.h" -#include "views/widget/native_widget.h" -#include "views/widget/widget_impl.h" -#include "views/widget/widget_impl_test_util.h" - -namespace views { - -class NativeWidgetTest : public testing::Test { - public: - NativeWidgetTest() {} - virtual ~NativeWidgetTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(NativeWidgetTest); -}; - -class TestWindowImpl : public ui::WindowImpl { - public: - TestWindowImpl() {} - virtual ~TestWindowImpl() {} - - virtual BOOL ProcessWindowMessage(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param, - LRESULT& result, - DWORD msg_mad_id = 0) { - return FALSE; - } - - private: - DISALLOW_COPY_AND_ASSIGN(TestWindowImpl); -}; - -#if 0 - -TEST_F(NativeWidgetTest, CreateNativeWidget) { - scoped_ptr<WidgetImpl> widget(internal::CreateWidgetImpl()); - EXPECT_TRUE(widget->native_widget()->GetNativeView() != NULL); -} - -TEST_F(NativeWidgetTest, GetNativeWidgetForNativeView) { - scoped_ptr<WidgetImpl> widget(internal::CreateWidgetImpl()); - NativeWidget* a = widget->native_widget(); - HWND nv = widget->native_widget()->GetNativeView(); - NativeWidget* b = NativeWidget::GetNativeWidgetForNativeView(nv); - EXPECT_EQ(a, b); -} - -// |widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget1) { - scoped_ptr<WidgetImpl> widget(internal::CreateWidgetImpl()); - EXPECT_EQ(widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - widget->native_widget()->GetNativeView())); -} - -// |toplevel_widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget2) { - scoped_ptr<WidgetImpl> child_widget(internal::CreateWidgetImpl()); - scoped_ptr<WidgetImpl> toplevel_widget(internal::CreateWidgetImpl()); - SetParent(child_widget->native_widget()->GetNativeView(), - toplevel_widget->native_widget()->GetNativeView()); - EXPECT_EQ(toplevel_widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - child_widget->native_widget()->GetNativeView())); -} - -// |child_widget| has the toplevel NativeWidget. -TEST_F(NativeWidgetTest, GetTopLevelNativeWidget3) { - scoped_ptr<WidgetImpl> child_widget(internal::CreateWidgetImpl()); - - TestWindowImpl toplevel; - toplevel.Init(NULL, gfx::Rect(10, 10, 100, 100)); - - SetParent(child_widget->native_widget()->GetNativeView(), toplevel.hwnd()); - EXPECT_EQ(child_widget->native_widget(), - NativeWidget::GetTopLevelNativeWidget( - child_widget->native_widget()->GetNativeView())); -} - -#endif - -} // namespace views diff --git a/views/widget/widget_impl.cc b/views/widget/widget_impl.cc deleted file mode 100644 index cd13ea8..0000000 --- a/views/widget/widget_impl.cc +++ /dev/null @@ -1,456 +0,0 @@ -// Copyright (c) 2011 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 "views/widget/widget_impl.h" - -#include "base/compiler_specific.h" -#include "base/message_loop.h" -#include "views/focus/focus_manager.h" -#include "views/focus/view_storage.h" -#include "views/view.h" -#include "views/widget/native_widget.h" -#include "views/widget/root_view.h" - -namespace views { - -namespace { - -// TODO(beng): move to platform file -int GetHorizontalDragThreshold() { - static int threshold = -1; -#if defined(OS_WIN) - if (threshold == -1) - threshold = GetSystemMetrics(SM_CXDRAG) / 2; -#endif - return threshold; -} - -// TODO(beng): move to platform file -int GetVerticalDragThreshold() { - static int threshold = -1; -#if defined(OS_WIN) - if (threshold == -1) - threshold = GetSystemMetrics(SM_CYDRAG) / 2; -#endif - return threshold; -} - -bool ExceededDragThreshold(int delta_x, int delta_y) { - return (abs(delta_x) > GetHorizontalDragThreshold() || - abs(delta_y) > GetVerticalDragThreshold()); -} - -} - -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, public: - -WidgetImpl::WidgetImpl(View* contents_view) - : ALLOW_THIS_IN_INITIALIZER_LIST( - native_widget_(NativeWidget::CreateNativeWidget(this))), - ALLOW_THIS_IN_INITIALIZER_LIST(root_view_(new RootView(this))), - contents_view_(contents_view), - is_mouse_button_pressed_(false), - last_mouse_event_was_move_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)), - delete_on_destroy_(true), - dragged_view_(NULL) { -} - -WidgetImpl::~WidgetImpl() { -} - -void WidgetImpl::InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds) { - native_widget_->InitWithNativeViewParent(parent, bounds); -} - -WidgetImpl* WidgetImpl::GetTopLevelWidgetImpl() const { - NativeWidget* native_widget = - NativeWidget::GetTopLevelNativeWidget(native_widget_->GetNativeView()); - return native_widget->GetWidgetImpl(); -} - -gfx::Rect WidgetImpl::GetWindowScreenBounds() const { - return native_widget_->GetWindowScreenBounds(); -} - -gfx::Rect WidgetImpl::GetClientAreaScreenBounds() const { - return native_widget_->GetClientAreaScreenBounds(); -} - -void WidgetImpl::SetBounds(const gfx::Rect& bounds) { - native_widget_->SetBounds(bounds); -} - -void WidgetImpl::SetShape(const gfx::Path& shape) { - native_widget_->SetShape(shape); -} - -void WidgetImpl::Show() { - native_widget_->Show(); -} - -void WidgetImpl::Hide() { - native_widget_->Hide(); -} - -void WidgetImpl::Close() { - native_widget_->Hide(); - - if (close_widget_factory_.empty()) { - MessageLoop::current()->PostTask(FROM_HERE, - close_widget_factory_.NewRunnableMethod(&WidgetImpl::CloseNow)); - } -} - -void WidgetImpl::MoveAbove(WidgetImpl* other) { - native_widget_->MoveAbove(other->native_widget()); -} - -void WidgetImpl::SetAlwaysOnTop(bool always_on_top) { - NOTIMPLEMENTED(); -} - -void WidgetImpl::SchedulePaintInRect(const gfx::Rect& invalid_rect) { - native_widget_->SchedulePaintInRect(invalid_rect); -} - -void WidgetImpl::SetCursor(gfx::NativeCursor cursor) { - native_widget_->SetCursor(cursor); -} - -FocusTraversable* WidgetImpl::GetFocusTraversable() { - return root_view_.get(); -} - -ThemeProvider* WidgetImpl::GetThemeProvider() const { - return NULL; -} - -void WidgetImpl::ThemeChanged() { - root_view_->ThemeChanged(); -} - -void WidgetImpl::LocaleChanged() { - root_view_->LocaleChanged(); -} - -FocusManager* WidgetImpl::GetFocusManager() { - return GetTopLevelWidgetImpl()->focus_manager_.get(); -} - -FocusTraversable* WidgetImpl::GetFocusTraversable() const { - return root_view_.get(); -} - -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, NativeWidgetListener implementation: - -void WidgetImpl::OnClose() { - Close(); -} - -void WidgetImpl::OnDestroy() { - if (delete_on_destroy_) - delete this; -} - -void WidgetImpl::OnDisplayChanged() { - // TODO(beng): -} - -bool WidgetImpl::OnKeyEvent(const KeyEvent& event) { - // find root view. - - //return root_view_->OnKeyEvent(event); - return true; -} - -void WidgetImpl::OnMouseCaptureLost() { - if (native_widget_->HasMouseCapture()) { - if (is_mouse_button_pressed_) { - // TODO(beng): Rename to OnMouseCaptureLost(); - root_view_->ProcessMouseDragCanceled(); - } - is_mouse_button_pressed_ = false; - } -} - -bool WidgetImpl::OnMouseEvent(const MouseEvent& event) { - last_mouse_event_was_move_ = false; - switch (event.type()) { - case ui::ET_MOUSE_PRESSED: - if (root_view_->OnMousePressed(event)) { - is_mouse_button_pressed_ = true; - if (!native_widget_->HasMouseCapture()) - native_widget_->SetMouseCapture(); - return true; - } - return false; - case ui::ET_MOUSE_RELEASED: - // TODO(beng): NativeWidgetGtk should not call this function if drag data - // exists, see comment in this function in WidgetGtk. - // Release the capture first, that way we don't get confused if - // OnMouseReleased blocks. - if (native_widget_->HasMouseCapture() && - native_widget_->ShouldReleaseCaptureOnMouseReleased()) { - native_widget_->ReleaseMouseCapture(); - } - is_mouse_button_pressed_ = false; - root_view_->OnMouseReleased(event, false); - return true; - case ui::ET_MOUSE_MOVED: - if (native_widget_->HasMouseCapture() && is_mouse_button_pressed_) { - last_mouse_event_was_move_ = false; - root_view_->OnMouseDragged(event); - } else { - gfx::Point screen_loc(event.location()); - View::ConvertPointToScreen(root_view_.get(), &screen_loc); - if (last_mouse_event_was_move_ && - last_mouse_event_position_ == screen_loc) { - // Don't generate a mouse event for the same location as the last. - return true; - } - last_mouse_event_position_ = screen_loc; - last_mouse_event_was_move_ = true; - root_view_->OnMouseMoved(event); - } - break; - case ui::ET_MOUSE_EXITED: - // TODO(beng): rename to OnMouseExited(event); - root_view_->ProcessOnMouseExited(); - return true; - default: - break; - } - return true; -} - -bool WidgetImpl::OnMouseWheelEvent(const MouseWheelEvent& event) { - // TODO(beng): rename to OnMouseWheel(event); - return !root_view_->ProcessMouseWheelEvent(event); -} - -void WidgetImpl::OnNativeWidgetCreated() { - root_view_->SetContentsView(contents_view_); - if (GetTopLevelWidgetImpl() == this) - focus_manager_.reset(new FocusManager(this)); -} - -void WidgetImpl::OnPaint(gfx::Canvas* canvas) { - root_view_->Paint(canvas); -} - -void WidgetImpl::OnSizeChanged(const gfx::Size& size) { - root_view_->SetSize(size); -} - -void WidgetImpl::OnNativeFocus(gfx::NativeView focused_view) { - GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( - focused_view, native_widget_->GetNativeView()); -} - -void WidgetImpl::OnNativeBlur(gfx::NativeView focused_view) { - GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( - native_widget_->GetNativeView(), focused_view); -} - -void WidgetImpl::OnWorkAreaChanged() { - -} - -WidgetImpl* WidgetImpl::GetWidgetImpl() { - return const_cast<WidgetImpl*>(const_cast<const WidgetImpl*>(this)); -} - -const WidgetImpl* WidgetImpl::GetWidgetImpl() const { - return this; -} - -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, Widget implementation: (TEMPORARY, TEMPORARY, TEMPORARY!) - -void WidgetImpl::Init(gfx::NativeView parent, const gfx::Rect& bounds) { - InitWithNativeViewParent(parent, bounds); -} - -void WidgetImpl::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { - NOTIMPLEMENTED(); -} - -WidgetDelegate* WidgetImpl::GetWidgetDelegate() { - NOTIMPLEMENTED(); - return NULL; -} - -void WidgetImpl::SetWidgetDelegate(WidgetDelegate* delegate) { - NOTIMPLEMENTED(); -} - -void WidgetImpl::SetContentsView(View* view) { - NOTIMPLEMENTED(); -} - -void WidgetImpl::GetBounds(gfx::Rect* out, bool including_frame) const { - NOTIMPLEMENTED(); -} - -void WidgetImpl::MoveAbove(Widget* widget) { - NativeWidget* other = - NativeWidget::GetNativeWidgetForNativeView(widget->GetNativeView()); - if (other) - native_widget_->MoveAbove(other); -} - -void WidgetImpl::SetShape(gfx::NativeRegion region) { - NOTIMPLEMENTED(); -} - -gfx::NativeView WidgetImpl::GetNativeView() const { - return native_widget_->GetNativeView(); -} - -void WidgetImpl::SetOpacity(unsigned char opacity) { - NOTIMPLEMENTED(); -} - -RootView* WidgetImpl::GetRootView() { - return root_view_.get(); -} - -Widget* WidgetImpl::GetRootWidget() const { - NOTIMPLEMENTED(); - return NULL; -} - -bool WidgetImpl::IsVisible() const { - NOTIMPLEMENTED(); - return false; -} - -bool WidgetImpl::IsActive() const { - NOTIMPLEMENTED(); - return false; -} - -bool WidgetImpl::IsAccessibleWidget() const { - NOTIMPLEMENTED(); - return false; -} - -TooltipManager* WidgetImpl::GetTooltipManager() { - NOTIMPLEMENTED(); - return NULL; -} - -void WidgetImpl::GenerateMousePressedForView(View* view, - const gfx::Point& point) { - NOTIMPLEMENTED(); -} - -bool WidgetImpl::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { - return false; -} - -Window* WidgetImpl::GetWindow() { - return NULL; -} - -const Window* WidgetImpl::GetWindow() const { - return NULL; -} - -void WidgetImpl::SetNativeWindowProperty(const char* name, void* value) { - native_widget_->SetNativeWindowProperty(name, value); -} - -void* WidgetImpl::GetNativeWindowProperty(const char* name) { - return native_widget_->GetNativeWindowProperty(name); -} - -ThemeProvider* WidgetImpl::GetDefaultThemeProvider() const { - NOTIMPLEMENTED(); - return NULL; -} - -void WidgetImpl::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - if (!is_add) { - if (child == dragged_view_) - dragged_view_ = NULL; - FocusManager* focus_manager = GetFocusManager(); - if (focus_manager) { - if (focus_manager->GetFocusedView() == child) - focus_manager->SetFocusedView(NULL); - focus_manager->ViewRemoved(parent, child); - } - ViewStorage::GetInstance()->ViewRemoved(parent, child); - } -} - -bool WidgetImpl::ContainsNativeView(gfx::NativeView native_view) { - NOTIMPLEMENTED(); - return false; -} - -void WidgetImpl::StartDragForViewFromMouseEvent( - View* view, - const OSExchangeData& data, - int operation) { - // NOTE: view may be NULL. - dragged_view_ = view; - native_widget_->RunShellDrag(data, operation); - - // If the view is removed during the drag operation, dragged_view_ is set to - // NULL. - if (view && dragged_view_ == view) { - dragged_view_ = NULL; - view->OnDragDone(); - } -} - -View* WidgetImpl::GetDraggedView() { - return dragged_view_; -} - -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, private: - -void WidgetImpl::CloseNow() { - native_widget_->Close(); -} - -#if !defined(OS_WIN) - -//////////////////////////////////////////////////////////////////////////////// -// NativeWidget, public: - -// static -NativeWidget* NativeWidget::CreateNativeWidget( - internal::NativeWidgetListener* listener) { - return NULL; -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeView( - gfx::NativeView native_view) { - return NULL; -} - -// static -NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow( - gfx::NativeWindow native_window) { - return NULL; -} - -// static -NativeWidget* NativeWidget::GetTopLevelNativeWidget( - gfx::NativeView native_view) { - return NULL; -} - -#endif // !defined(OS_WIN) - -} // namespace views - diff --git a/views/widget/widget_impl.h b/views/widget/widget_impl.h deleted file mode 100644 index 0ba7025..0000000 --- a/views/widget/widget_impl.h +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_WIDGET_WIDGET_IMPL_H_ -#define VIEWS_WIDGET_WIDGET_IMPL_H_ - -#include "base/logging.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "ui/gfx/point.h" -#include "views/native_types.h" -#include "views/focus/focus_manager.h" -#include "views/widget/native_widget_listener.h" -#include "views/widget/widget.h" - -namespace gfx { -class Canvas; -class Path; -class Rect; -class Size; -} - -namespace ui { - class ThemeProvider; -} - -namespace views { -class FocusManager; -class KeyEvent; -class MouseEvent; -class MouseWheelEvent; -class NativeWidget; -class RootView; -class View; - -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl class -// -// Encapsulates the platform-specific rendering, event receiving and widget -// management aspects of the UI framework. -// -// Owns a RootView and thus a View hierarchy. Can contain child WidgetImpls. -// WidgetImpl is a platform-independent type that communicates with a platform -// or context specific NativeWidget implementation. -// -// TODO(beng): Consider ownership of this object vs. NativeWidget. -class WidgetImpl : public internal::NativeWidgetListener, - public Widget { - public: - explicit WidgetImpl(View* contents_view); - virtual ~WidgetImpl(); - - void set_delete_on_destroy(bool delete_on_destroy) { - delete_on_destroy_ = delete_on_destroy; - } - - // Initialization. - void InitWithNativeViewParent(gfx::NativeView parent, - const gfx::Rect& bounds); - - // Returns the topmost WidgetImpl in a hierarchy. - WidgetImpl* GetTopLevelWidgetImpl() const; - - // Returns the bounding rect of the Widget in screen coordinates. - gfx::Rect GetWindowScreenBounds() const; - - // Returns the bounding rect of the Widget's client area, in screen - // coordinates. - gfx::Rect GetClientAreaScreenBounds() const; - - // Sets the bounding rect of the Widget, in the coordinate system of its - // parent. - void SetBounds(const gfx::Rect& bounds); - - void SetShape(const gfx::Path& shape); - - void Show(); - void Hide(); - - void Close(); - - void MoveAbove(WidgetImpl* other); - void SetAlwaysOnTop(bool always_on_top); - - // Causes the specified rectangle to be added to the invalid rectangle for the - // WidgetImpl. - void SchedulePaintInRect(const gfx::Rect& rect); - - void SetCursor(gfx::NativeCursor cursor); - - FocusTraversable* GetFocusTraversable(); - - // Returns a ThemeProvider that can be used to provide resources when - // rendering Views associated with this WidgetImpl. - ThemeProvider* GetThemeProvider() const; - - void ThemeChanged(); - void LocaleChanged(); - - // Returns the FocusManager for this WidgetImpl. Only top-level WidgetImpls - // have FocusManagers. - FocusManager* GetFocusManager(); - - FocusTraversable* GetFocusTraversable() const; - - NativeWidget* native_widget() const { return native_widget_.get(); } - - private: - // Overridden from internal::NativeWidgetListener: - virtual void OnClose(); - virtual void OnDestroy(); - virtual void OnDisplayChanged(); - virtual bool OnKeyEvent(const KeyEvent& event); - virtual void OnMouseCaptureLost(); - virtual bool OnMouseEvent(const MouseEvent& event); - virtual bool OnMouseWheelEvent(const MouseWheelEvent& event); - virtual void OnNativeWidgetCreated(); - virtual void OnPaint(gfx::Canvas* canvas); - virtual void OnSizeChanged(const gfx::Size& size); - virtual void OnNativeFocus(gfx::NativeView focused_view); - virtual void OnNativeBlur(gfx::NativeView focused_view); - virtual void OnWorkAreaChanged(); - virtual WidgetImpl* GetWidgetImpl(); - virtual const WidgetImpl* GetWidgetImpl() const; - - // Overridden from Widget: - // TODO(beng): THIS IS TEMPORARY, and excludes methods duplicated above in - // new WidgetImpl API. - // TODO(beng): Remove/Merge with WidgetImpl API above. - virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); - virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); - virtual WidgetDelegate* GetWidgetDelegate(); - virtual void SetWidgetDelegate(WidgetDelegate* delegate); - virtual void SetContentsView(View* view); - virtual void GetBounds(gfx::Rect* out, bool including_frame) const; - virtual void MoveAbove(Widget* widget); - virtual void SetShape(gfx::NativeRegion region); - virtual gfx::NativeView GetNativeView() const; - virtual void SetOpacity(unsigned char opacity); - virtual RootView* GetRootView(); - virtual Widget* GetRootWidget() const; - virtual bool IsVisible() const; - virtual bool IsActive() const; - virtual bool IsAccessibleWidget() const; - virtual TooltipManager* GetTooltipManager(); - virtual void GenerateMousePressedForView(View* view, - const gfx::Point& point); - virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); - virtual Window* GetWindow(); - virtual const Window* GetWindow() const; - virtual void SetNativeWindowProperty(const char* name, void* value); - virtual void* GetNativeWindowProperty(const char* name); - virtual ThemeProvider* GetDefaultThemeProvider() const; - virtual void ViewHierarchyChanged(bool is_add, View *parent, - View *child); - virtual bool ContainsNativeView(gfx::NativeView native_view); - virtual void StartDragForViewFromMouseEvent(View* view, - const OSExchangeData& data, - int operation); - virtual View* GetDraggedView(); - - // Causes the Widget to be destroyed immediately. - void CloseNow(); - - // A NativeWidget implementation. This can be changed dynamically to a - // different implementation during the lifetime of the Widget. - scoped_ptr<NativeWidget> native_widget_; - - // A RootView that owns the View hierarchy within this Widget. - scoped_ptr<RootView> root_view_; - // TODO(beng): Remove once we upgrade RootView. - View* contents_view_; - - // True when any mouse button is pressed. - bool is_mouse_button_pressed_; - - // The following are used to detect duplicate mouse move events and not - // deliver them. Displaying a window may result in the system generating - // duplicate move events even though the mouse hasn't moved. - bool last_mouse_event_was_move_; - gfx::Point last_mouse_event_position_; - - // Handles closing the Widget after a return to the message loop to allow the - // stack to unwind. - ScopedRunnableMethodFactory<WidgetImpl> close_widget_factory_; - - // True if the Widget should be automatically deleted when it is destroyed. - bool delete_on_destroy_; - - scoped_ptr<FocusManager> focus_manager_; - - // Valid for the lifetime of StartDragForViewFromMouseEvent, indicates the - // view the drag started from. NULL at all other times. - View* dragged_view_; - - DISALLOW_COPY_AND_ASSIGN(WidgetImpl); -}; - -} // namespace views - -#endif // VIEWS_WIDGET_WIDGET_IMPL_H_ - diff --git a/views/widget/widget_impl_test_util.cc b/views/widget/widget_impl_test_util.cc deleted file mode 100644 index 4339e7e..0000000 --- a/views/widget/widget_impl_test_util.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2011 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 "views/widget/widget_impl_test_util.h" - -#include "views/view.h" -#include "views/widget/native_widget.h" -#include "views/widget/widget_impl.h" - -namespace views { -namespace internal { - -WidgetImpl* CreateWidgetImpl() { - return CreateWidgetImplWithContents(new View); -} - -WidgetImpl* CreateWidgetImplWithContents(View* contents_view) { - WidgetImpl* widget = new WidgetImpl(contents_view); - widget->set_delete_on_destroy(false); - widget->InitWithNativeViewParent(NULL, gfx::Rect(10, 10, 200, 200)); - return widget; -} - -WidgetImpl* CreateWidgetImplWithParent(WidgetImpl* parent) { - WidgetImpl* widget = new WidgetImpl(new View); - widget->set_delete_on_destroy(false); - widget->InitWithNativeViewParent(parent->native_widget()->GetNativeView(), - gfx::Rect(10, 10, 200, 200)); - return widget; -} - -} // namespace internal -} // namespace views diff --git a/views/widget/widget_impl_test_util.h b/views/widget/widget_impl_test_util.h deleted file mode 100644 index 5609397..0000000 --- a/views/widget/widget_impl_test_util.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2011 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 VIEWS_WIDGET_WIDGET_IMPL_TEST_UTIL_H_ -#define VIEWS_WIDGET_WIDGET_IMPL_TEST_UTIL_H_ -#pragma once - -namespace views { -class View; -class WidgetImpl; -namespace internal { - -// Create dummy WidgetImpls for use in testing. -WidgetImpl* CreateWidgetImpl(); -WidgetImpl* CreateWidgetImplWithContents(View* contents_view); -WidgetImpl* CreateWidgetImplWithParent(WidgetImpl* parent); - -} // namespace internal -} // namespace views - -#endif // VIEWS_WIDGET_WIDGET_IMPL_TEST_UTIL_H_ diff --git a/views/widget/widget_impl_unittest.cc b/views/widget/widget_impl_unittest.cc deleted file mode 100644 index 057ed1d..0000000 --- a/views/widget/widget_impl_unittest.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2011 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 "base/logging.h" -#include "base/scoped_ptr.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "views/focus/focus_manager.h" -#include "views/widget/native_widget.h" -#include "views/widget/widget_impl.h" -#include "views/widget/widget_impl_test_util.h" - -namespace views { - -class WidgetTest : public testing::Test { - public: - WidgetTest() {} - virtual ~WidgetTest() {} - - private: - DISALLOW_COPY_AND_ASSIGN(WidgetTest); -}; - -TEST_F(WidgetTest, FocusManagerInit_Basic) { - scoped_ptr<WidgetImpl> widget(internal::CreateWidgetImpl()); - EXPECT_TRUE(widget->GetFocusManager() != NULL); -} - -TEST_F(WidgetTest, FocusManagerInit_Nested) { - scoped_ptr<WidgetImpl> parent(internal::CreateWidgetImpl()); - scoped_ptr<WidgetImpl> child( - internal::CreateWidgetImplWithParent(parent.get())); - - EXPECT_EQ(parent->GetFocusManager(), child->GetFocusManager()); -} - -} // namespace views - |