diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 04:24:41 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-15 04:24:41 +0000 |
commit | 4101aebea15c3b1411a017a19f1df97fd2a4ffcb (patch) | |
tree | 4cb81322bef4f8313f5edc4b833c7893b0279c8c /views/widget/widget_impl.cc | |
parent | a769d6e25f36e3b6fa1580d932117a7aa7021cdc (diff) | |
download | chromium_src-4101aebea15c3b1411a017a19f1df97fd2a4ffcb.zip chromium_src-4101aebea15c3b1411a017a19f1df97fd2a4ffcb.tar.gz chromium_src-4101aebea15c3b1411a017a19f1df97fd2a4ffcb.tar.bz2 |
Begin implementing a new widget.
This brings over code from ui/views, and bandaids it into compiling with the existing RootView/Widget interface. It compiles but probably doesn't run, which is OK since no one uses it.
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/6523008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74915 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget/widget_impl.cc')
-rw-r--r-- | views/widget/widget_impl.cc | 355 |
1 files changed, 275 insertions, 80 deletions
diff --git a/views/widget/widget_impl.cc b/views/widget/widget_impl.cc index c3292c9..0063a71 100644 --- a/views/widget/widget_impl.cc +++ b/views/widget/widget_impl.cc @@ -4,217 +4,412 @@ #include "views/widget/widget_impl.h" +#include "base/compiler_specific.h" +#include "base/message_loop.h" +#include "views/focus/focus_manager.h" +#include "views/view.h" +#include "views/widget/native_widget.h" +#include "views/widget/root_view.h" + namespace views { -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, public: +namespace { -WidgetImpl::WidgetImpl() { +// 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; } -WidgetImpl::~WidgetImpl() { +// 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; } -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, Widget implementation: - -void WidgetImpl::Init(gfx::NativeView parent, const gfx::Rect& bounds) { +bool ExceededDragThreshold(int delta_x, int delta_y) { + return (abs(delta_x) > GetHorizontalDragThreshold() || + abs(delta_y) > GetVerticalDragThreshold()); +} } -void WidgetImpl::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { +//////////////////////////////////////////////////////////////////////////////// +// 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) { } -WidgetDelegate* WidgetImpl::GetWidgetDelegate() { - return NULL; +WidgetImpl::~WidgetImpl() { } -void WidgetImpl::SetWidgetDelegate(WidgetDelegate* delegate) { - +void WidgetImpl::InitWithNativeViewParent(gfx::NativeView parent, + const gfx::Rect& bounds) { + native_widget_->InitWithNativeViewParent(parent, bounds); } -void WidgetImpl::SetContentsView(View* view) { - +WidgetImpl* WidgetImpl::GetTopLevelWidgetImpl() const { + NativeWidget* native_widget = + NativeWidget::GetTopLevelNativeWidget(native_widget_->GetNativeView()); + return native_widget->GetWidgetImpl(); } -void WidgetImpl::GetBounds(gfx::Rect* out, bool including_frame) const { +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::MoveAbove(Widget* other) { - +void WidgetImpl::SetShape(const gfx::Path& shape) { + native_widget_->SetShape(shape); } -void WidgetImpl::SetShape(gfx::NativeRegion region) { +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::CloseNow() { - +void WidgetImpl::MoveAbove(WidgetImpl* other) { + native_widget_->MoveAbove(other->native_widget()); } -void WidgetImpl::Show() { +void WidgetImpl::SetAlwaysOnTop(bool always_on_top) { + NOTIMPLEMENTED(); +} +void WidgetImpl::InvalidateRect(const gfx::Rect& invalid_rect) { + native_widget_->InvalidateRect(invalid_rect); } -void WidgetImpl::Hide() { +ThemeProvider* WidgetImpl::GetThemeProvider() const { + return NULL; +} +FocusManager* WidgetImpl::GetFocusManager() { + return GetTopLevelWidgetImpl()->focus_manager_.get(); } -gfx::NativeView WidgetImpl::GetNativeView() const { - return NULL; +FocusTraversable* WidgetImpl::GetFocusTraversable() const { + return root_view_.get(); } -void WidgetImpl::PaintNow(const gfx::Rect& update_rect) { +//////////////////////////////////////////////////////////////////////////////// +// WidgetImpl, NativeWidgetListener implementation: +void WidgetImpl::OnClose() { + Close(); } -void WidgetImpl::SetOpacity(unsigned char opacity) { +void WidgetImpl::OnDestroy() { + if (delete_on_destroy_) + delete this; +} + +void WidgetImpl::OnDisplayChanged() { + // TODO(beng): } -void WidgetImpl::SetAlwaysOnTop(bool on_top) { +bool WidgetImpl::OnKeyEvent(const KeyEvent& event) { + // find root view. + //return root_view_->OnKeyEvent(event); + return true; } -RootView* WidgetImpl::GetRootView() { - return NULL; +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; + } } -Widget* WidgetImpl::GetRootWidget() const { - return NULL; +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::IsVisible() const { - return false; +bool WidgetImpl::OnMouseWheelEvent(const MouseWheelEvent& event) { + // TODO(beng): rename to OnMouseWheel(event); + return !root_view_->ProcessMouseWheelEvent(event); } -bool WidgetImpl::IsActive() const { - return false; +void WidgetImpl::OnNativeWidgetCreated() { + root_view_->SetContentsView(contents_view_); + if (GetTopLevelWidgetImpl() == this) + focus_manager_.reset(new FocusManager(this)); } -bool WidgetImpl::IsAccessibleWidget() const { - return false; +void WidgetImpl::OnPaint(gfx::Canvas* canvas) { + // TODO(beng): replace with root_view_->Paint(canvas); +#if defined(OS_WIN) + root_view_->OnPaint(native_widget_->GetNativeView()); +#endif } -TooltipManager* WidgetImpl::GetTooltipManager() { - return NULL; +void WidgetImpl::OnSizeChanged(const gfx::Size& size) { + root_view_->SetSize(size); } -void WidgetImpl::GenerateMousePressedForView(View* view, - const gfx::Point& point) { +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); } -bool WidgetImpl::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { - return false; +void WidgetImpl::OnWorkAreaChanged() { + } -Window* WidgetImpl::GetWindow() { - return NULL; +WidgetImpl* WidgetImpl::GetWidgetImpl() { + return const_cast<WidgetImpl*>(const_cast<const WidgetImpl*>(this)); } -const Window* WidgetImpl::GetWindow() const { - return NULL; +const WidgetImpl* WidgetImpl::GetWidgetImpl() const { + return this; } -void WidgetImpl::SetNativeWindowProperty(const char* name, void* value) { +//////////////////////////////////////////////////////////////////////////////// +// WidgetImpl, Widget implementation: (TEMPORARY, TEMPORARY, TEMPORARY!) +void WidgetImpl::Init(gfx::NativeView parent, const gfx::Rect& bounds) { + InitWithNativeViewParent(parent, bounds); } -void* WidgetImpl::GetNativeWindowProperty(const char* name) { - return NULL; +void WidgetImpl::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { + NOTIMPLEMENTED(); } -ThemeProvider* WidgetImpl::GetThemeProvider() const { +WidgetDelegate* WidgetImpl::GetWidgetDelegate() { + NOTIMPLEMENTED(); return NULL; } -ThemeProvider* WidgetImpl::GetDefaultThemeProvider() const { - return NULL; +void WidgetImpl::SetWidgetDelegate(WidgetDelegate* delegate) { + NOTIMPLEMENTED(); } -FocusManager* WidgetImpl::GetFocusManager() { - return NULL; +void WidgetImpl::SetContentsView(View* view) { + NOTIMPLEMENTED(); } -void WidgetImpl::ViewHierarchyChanged(bool is_add, View *parent, - View *child) { +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); } -bool WidgetImpl::ContainsNativeView(gfx::NativeView native_view) { - return false; +void WidgetImpl::SetShape(gfx::NativeRegion region) { + NOTIMPLEMENTED(); } -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, NativeWidgetListener implementation: +gfx::NativeView WidgetImpl::GetNativeView() const { + return native_widget_->GetNativeView(); +} -void WidgetImpl::OnClose() { +void WidgetImpl::PaintNow(const gfx::Rect& update_rect) { + NOTIMPLEMENTED(); +} +void WidgetImpl::SetOpacity(unsigned char opacity) { + NOTIMPLEMENTED(); } -void WidgetImpl::OnDestroy() { +RootView* WidgetImpl::GetRootView() { + return root_view_.get(); +} +Widget* WidgetImpl::GetRootWidget() const { + NOTIMPLEMENTED(); + return NULL; } -void WidgetImpl::OnDisplayChanged() { +bool WidgetImpl::IsVisible() const { + NOTIMPLEMENTED(); + return false; +} +bool WidgetImpl::IsActive() const { + NOTIMPLEMENTED(); + return false; } -bool WidgetImpl::OnKeyEvent(const KeyEvent& event) { +bool WidgetImpl::IsAccessibleWidget() const { + NOTIMPLEMENTED(); return false; } -void WidgetImpl::OnMouseCaptureLost() { +TooltipManager* WidgetImpl::GetTooltipManager() { + NOTIMPLEMENTED(); + return NULL; +} +void WidgetImpl::GenerateMousePressedForView(View* view, + const gfx::Point& point) { + NOTIMPLEMENTED(); } -bool WidgetImpl::OnMouseEvent(const MouseEvent& event) { +bool WidgetImpl::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { return false; } -bool WidgetImpl::OnMouseWheelEvent(const MouseWheelEvent& event) { - return false; +Window* WidgetImpl::GetWindow() { + return NULL; } -void WidgetImpl::OnNativeWidgetCreated() { +const Window* WidgetImpl::GetWindow() const { + return NULL; +} +void WidgetImpl::SetNativeWindowProperty(const char* name, void* value) { + native_widget_->SetNativeWindowProperty(name, value); } -void WidgetImpl::OnPaint(gfx::Canvas* canvas) { +void* WidgetImpl::GetNativeWindowProperty(const char* name) { + return native_widget_->GetNativeWindowProperty(name); +} +ThemeProvider* WidgetImpl::GetDefaultThemeProvider() const { + NOTIMPLEMENTED(); + return NULL; } -void WidgetImpl::OnSizeChanged(const gfx::Size& size) { +void WidgetImpl::ViewHierarchyChanged(bool is_add, View* parent, View* child) { + NOTIMPLEMENTED(); +} +bool WidgetImpl::ContainsNativeView(gfx::NativeView native_view) { + NOTIMPLEMENTED(); + return false; } -void WidgetImpl::OnNativeFocus(gfx::NativeView focused_view) { +//////////////////////////////////////////////////////////////////////////////// +// WidgetImpl, private: +void WidgetImpl::CloseNow() { + native_widget_->Close(); } -void WidgetImpl::OnNativeBlur(gfx::NativeView focused_view) { +#if !defined(OS_WIN) +//////////////////////////////////////////////////////////////////////////////// +// NativeWidget, public: + +// static +NativeWidget* NativeWidget::CreateNativeWidget( + internal::NativeWidgetListener* listener) { + return NULL; } -void WidgetImpl::OnWorkAreaChanged() { +// static +NativeWidget* NativeWidget::GetNativeWidgetForNativeView( + gfx::NativeView native_view) { + return NULL; +} +// static +NativeWidget* NativeWidget::GetNativeWidgetForNativeWindow( + gfx::NativeWindow native_window) { + return NULL; } -WidgetImpl* WidgetImpl::GetWidgetImpl() const { +// static +NativeWidget* NativeWidget::GetTopLevelNativeWidget( + gfx::NativeView native_view) { return NULL; } -//////////////////////////////////////////////////////////////////////////////// -// WidgetImpl, private: +#endif // !defined(OS_WIN) } // namespace views + |