summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 05:39:26 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-20 05:39:26 +0000
commit080f34ff022299737619be0a6877b7b9b7910c54 (patch)
tree783192857c1e37f673c4540fb13f5444b05c8155 /views/widget
parent2f2ee5fb5fda64cce38f52adb139a6a499b58b29 (diff)
downloadchromium_src-080f34ff022299737619be0a6877b7b9b7910c54.zip
chromium_src-080f34ff022299737619be0a6877b7b9b7910c54.tar.gz
chromium_src-080f34ff022299737619be0a6877b7b9b7910c54.tar.bz2
Relanding 100792
Use TabContentsViewViews for RenderWidgetHostViweViews. * Removed TabContentsViewTouch. * Changed so that mouse and resize event goes through NativeWidgetViews so that NativeTabContentsViewViews can invoke NativeTabContentsViewDelegates. BUG=none TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=100792 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=100834 Review URL: http://codereview.chromium.org/7460001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101921 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/native_widget_aura.cc5
-rw-r--r--views/widget/native_widget_aura.h1
-rw-r--r--views/widget/native_widget_gtk.cc28
-rw-r--r--views/widget/native_widget_gtk.h1
-rw-r--r--views/widget/native_widget_private.h1
-rw-r--r--views/widget/native_widget_view.cc51
-rw-r--r--views/widget/native_widget_views.cc83
-rw-r--r--views/widget/native_widget_views.h12
-rw-r--r--views/widget/native_widget_win.cc4
-rw-r--r--views/widget/native_widget_win.h1
-rw-r--r--views/widget/widget.cc12
-rw-r--r--views/widget/widget.h5
12 files changed, 132 insertions, 72 deletions
diff --git a/views/widget/native_widget_aura.cc b/views/widget/native_widget_aura.cc
index cf22211..a939440 100644
--- a/views/widget/native_widget_aura.cc
+++ b/views/widget/native_widget_aura.cc
@@ -9,6 +9,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/font.h"
+#include "ui/gfx/screen.h"
#include "views/widget/native_widget_delegate.h"
#if defined(OS_WIN)
@@ -370,6 +371,10 @@ bool NativeWidgetAura::ConvertPointFromAncestor(const Widget* ancestor,
return false;
}
+gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const {
+ return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetAura, views::InputMethodDelegate implementation:
diff --git a/views/widget/native_widget_aura.h b/views/widget/native_widget_aura.h
index 8a115f1..7a2a927 100644
--- a/views/widget/native_widget_aura.h
+++ b/views/widget/native_widget_aura.h
@@ -109,6 +109,7 @@ class NativeWidgetAura : public internal::NativeWidgetPrivate,
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
virtual bool ConvertPointFromAncestor(
const Widget* ancestor, gfx::Point* point) const OVERRIDE;
+ virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
// Overridden from views::InputMethodDelegate:
virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index 5589f49..6a7973c 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -1332,6 +1332,10 @@ bool NativeWidgetGtk::ConvertPointFromAncestor(
return false;
}
+gfx::Rect NativeWidgetGtk::GetWorkAreaBoundsInScreen() const {
+ return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetGtk, protected:
@@ -2133,22 +2137,20 @@ bool Widget::ConvertRect(const Widget* source,
DCHECK(target);
DCHECK(rect);
- GtkWidget* source_widget = source->GetNativeView();
- GtkWidget* target_widget = target->GetNativeView();
- if (source_widget == target_widget)
- return true;
+ // TODO(oshima): Add check if source and target belongs to the same
+ // screen.
- if (!source_widget || !target_widget)
+ if (source == target)
+ return true;
+ if (!source || !target)
return false;
- GdkRectangle gdk_rect = rect->ToGdkRectangle();
- if (gtk_widget_translate_coordinates(source_widget, target_widget,
- gdk_rect.x, gdk_rect.y,
- &gdk_rect.x, &gdk_rect.y)) {
- *rect = gdk_rect;
- return true;
- }
- return false;
+ gfx::Point source_point = source->GetWindowScreenBounds().origin();
+ gfx::Point target_point = target->GetWindowScreenBounds().origin();
+
+ rect->set_origin(
+ source_point.Subtract(target_point).Add(rect->origin()));
+ return true;
}
namespace internal {
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index 0cdc9f2..152d462 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -220,6 +220,7 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
virtual bool ConvertPointFromAncestor(
const Widget* ancestor, gfx::Point* point) const OVERRIDE;
+ virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
protected:
// Modifies event coordinates to the targeted widget contained by this widget.
diff --git a/views/widget/native_widget_private.h b/views/widget/native_widget_private.h
index 43f0935..63471d4 100644
--- a/views/widget/native_widget_private.h
+++ b/views/widget/native_widget_private.h
@@ -203,6 +203,7 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget,
virtual void FocusNativeView(gfx::NativeView native_view) = 0;
virtual bool ConvertPointFromAncestor(
const Widget* ancestor, gfx::Point* point) const = 0;
+ virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0;
// Overridden from NativeWidget:
virtual internal::NativeWidgetPrivate* AsNativeWidgetPrivate() OVERRIDE;
diff --git a/views/widget/native_widget_view.cc b/views/widget/native_widget_view.cc
index aa327c6..7a6c554 100644
--- a/views/widget/native_widget_view.cc
+++ b/views/widget/native_widget_view.cc
@@ -5,10 +5,6 @@
#include "views/widget/native_widget_view.h"
#include "ui/gfx/canvas.h"
-#if defined(OS_LINUX)
-#include "views/window/hit_test.h"
-#endif
-#include "views/widget/window_manager.h"
namespace views {
namespace internal {
@@ -60,7 +56,7 @@ void NativeWidgetView::ViewHierarchyChanged(bool is_add,
}
void NativeWidgetView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
- delegate()->OnNativeWidgetSizeChanged(size());
+ native_widget_->OnBoundsChanged(bounds(), previous_bounds);
}
void NativeWidgetView::OnPaint(gfx::Canvas* canvas) {
@@ -72,46 +68,15 @@ gfx::NativeCursor NativeWidgetView::GetCursor(const MouseEvent& event) {
}
bool NativeWidgetView::OnMousePressed(const MouseEvent& event) {
- Widget* hosting_widget = GetAssociatedWidget();
- if (hosting_widget->non_client_view()) {
- int hittest_code = hosting_widget->non_client_view()->NonClientHitTest(
- event.location());
- switch (hittest_code) {
- case HTCAPTION: {
- if (!event.IsOnlyRightMouseButton()) {
- WindowManager::Get()->StartMoveDrag(hosting_widget, event.location());
- return true;
- }
- break;
- }
- case HTBOTTOM:
- case HTBOTTOMLEFT:
- case HTBOTTOMRIGHT:
- case HTGROWBOX:
- case HTLEFT:
- case HTRIGHT:
- case HTTOP:
- case HTTOPLEFT:
- case HTTOPRIGHT: {
- WindowManager::Get()->StartResizeDrag(
- hosting_widget, event.location(), hittest_code);
- return true;
- }
- default:
- // Everything else falls into standard client event handling...
- break;
- }
- }
-
- return delegate()->OnMouseEvent(event);
+ return native_widget_->OnMouseEvent(event);
}
bool NativeWidgetView::OnMouseDragged(const MouseEvent& event) {
- return delegate()->OnMouseEvent(event);
+ return native_widget_->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseReleased(const MouseEvent& event) {
- delegate()->OnMouseEvent(event);
+ native_widget_->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseCaptureLost() {
@@ -119,15 +84,15 @@ void NativeWidgetView::OnMouseCaptureLost() {
}
void NativeWidgetView::OnMouseMoved(const MouseEvent& event) {
- delegate()->OnMouseEvent(event);
+ native_widget_->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseEntered(const MouseEvent& event) {
- delegate()->OnMouseEvent(event);
+ native_widget_->OnMouseEvent(event);
}
void NativeWidgetView::OnMouseExited(const MouseEvent& event) {
- delegate()->OnMouseEvent(event);
+ native_widget_->OnMouseEvent(event);
}
ui::TouchStatus NativeWidgetView::OnTouchEvent(const TouchEvent& event) {
@@ -143,7 +108,7 @@ bool NativeWidgetView::OnKeyReleased(const KeyEvent& event) {
}
bool NativeWidgetView::OnMouseWheel(const MouseWheelEvent& event) {
- return delegate()->OnMouseEvent(event);
+ return native_widget_->OnMouseEvent(event);
}
void NativeWidgetView::VisibilityChanged(View* starting_from,
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index a61a9b9..c0d4af2 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -18,6 +18,10 @@
#include "views/ime/mock_input_method.h"
#endif
+#if defined(OS_LINUX)
+#include "views/window/hit_test.h"
+#endif
+
namespace views {
////////////////////////////////////////////////////////////////////////////////
@@ -30,7 +34,6 @@ NativeWidgetViews::NativeWidgetViews(internal::NativeWidgetDelegate* delegate)
minimized_(false),
always_on_top_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
- hosting_widget_(NULL),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
delete_native_view_(true) {
}
@@ -95,6 +98,18 @@ void NativeWidgetViews::DispatchKeyEventPostIME(const KeyEvent& key) {
}
////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetViews, protected:
+
+void NativeWidgetViews::OnBoundsChanged(const gfx::Rect& new_bounds,
+ const gfx::Rect& old_bounds) {
+ delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
+}
+
+bool NativeWidgetViews::OnMouseEvent(const MouseEvent& event) {
+ return HandleWindowOperation(event) ? true : delegate_->OnMouseEvent(event);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, NativeWidget implementation:
void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
@@ -102,18 +117,20 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
always_on_top_ = params.keep_on_top;
View* parent_view = NULL;
if (params.parent_widget) {
- hosting_widget_ = params.parent_widget;
- parent_view = hosting_widget_->GetChildViewParent();
- } else {
+ parent_view = params.parent_widget->GetChildViewParent();
+ } else if (ViewsDelegate::views_delegate &&
+ ViewsDelegate::views_delegate->GetDefaultParentView()) {
parent_view = ViewsDelegate::views_delegate->GetDefaultParentView();
- hosting_widget_ = parent_view->GetWidget();
+ } else if (params.parent) {
+ Widget* widget = Widget::GetWidgetForNativeView(params.parent);
+ parent_view = widget->GetChildViewParent();
}
view_ = new internal::NativeWidgetView(this);
view_->SetBoundsRect(params.bounds);
#if !defined(USE_AURA)
// TODO(beng): re-enable this once we have a consolidated layer tree.
- view_->SetPaintToLayer(true);
+ view_->SetPaintToLayer(params.create_layer);
#endif
// With the default NATIVE_WIDGET_OWNS_WIDGET ownership, the
@@ -124,7 +141,8 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
if (ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET)
view_->set_delete_native_widget(false);
- parent_view->AddChildView(view_);
+ if (parent_view)
+ parent_view->AddChildView(view_);
// TODO(beng): SetInitParams().
}
@@ -165,7 +183,8 @@ Widget* NativeWidgetViews::GetTopLevelWidget() {
// view_ has already been unset.
if (!view_)
return GetWidget();
- if (view_->parent() == ViewsDelegate::views_delegate->GetDefaultParentView())
+ if (ViewsDelegate::views_delegate &&
+ view_->parent() == ViewsDelegate::views_delegate->GetDefaultParentView())
return GetWidget();
// During Widget destruction, this function may be called after |view_| is
// detached from a Widget, at which point this NativeWidget's Widget becomes
@@ -176,11 +195,11 @@ Widget* NativeWidgetViews::GetTopLevelWidget() {
}
const ui::Compositor* NativeWidgetViews::GetCompositor() const {
- return hosting_widget_->GetCompositor();
+ return view_->GetWidget() ? view_->GetWidget()->GetCompositor() : NULL;
}
ui::Compositor* NativeWidgetViews::GetCompositor() {
- return hosting_widget_->GetCompositor();
+ return view_->GetWidget() ? view_->GetWidget()->GetCompositor() : NULL;
}
void NativeWidgetViews::CalculateOffsetToAncestorWithLayer(
@@ -504,6 +523,13 @@ bool NativeWidgetViews::ConvertPointFromAncestor(
return false;
}
+gfx::Rect NativeWidgetViews::GetWorkAreaBoundsInScreen() const {
+ // TODO(oshima): This should return the views desktop window's
+ // working area when the system is running under views desktop
+ // rather than native window's working area.
+ return GetParentNativeWidget()->GetWorkAreaBoundsInScreen();
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetViews, private:
@@ -522,4 +548,41 @@ const internal::NativeWidgetPrivate*
NULL;
}
+bool NativeWidgetViews::HandleWindowOperation(const MouseEvent& event) {
+ if (event.type() != ui::ET_MOUSE_PRESSED)
+ return false;
+
+ Widget* widget = GetWidget();
+ if (widget->non_client_view()) {
+ int hittest_code = widget->non_client_view()->NonClientHitTest(
+ event.location());
+ switch (hittest_code) {
+ case HTCAPTION: {
+ if (!event.IsOnlyRightMouseButton()) {
+ WindowManager::Get()->StartMoveDrag(widget, event.location());
+ return true;
+ }
+ break;
+ }
+ case HTBOTTOM:
+ case HTBOTTOMLEFT:
+ case HTBOTTOMRIGHT:
+ case HTGROWBOX:
+ case HTLEFT:
+ case HTRIGHT:
+ case HTTOP:
+ case HTTOPLEFT:
+ case HTTOPRIGHT: {
+ WindowManager::Get()->StartResizeDrag(
+ widget, event.location(), hittest_code);
+ return true;
+ }
+ default:
+ // Everything else falls into standard client event handling.
+ break;
+ }
+ }
+ return false;
+}
+
} // namespace views
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index 2600c32..3c43a57 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -47,7 +47,12 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate {
internal::NativeWidgetDelegate* delegate() const { return delegate_; }
protected:
- friend class NativeWidgetView;
+ friend class internal::NativeWidgetView;
+
+ // Event handlers that subclass can implmenet custom behavior.
+ virtual void OnBoundsChanged(const gfx::Rect& new_bounds,
+ const gfx::Rect& old_bounds);
+ virtual bool OnMouseEvent(const MouseEvent& event);
// Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
@@ -130,6 +135,7 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate {
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
virtual bool ConvertPointFromAncestor(
const Widget* ancestor, gfx::Point* point) const OVERRIDE;
+ virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
// Overridden from internal::InputMethodDelegate
virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
@@ -141,6 +147,8 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate {
internal::NativeWidgetPrivate* GetParentNativeWidget();
const internal::NativeWidgetPrivate* GetParentNativeWidget() const;
+ bool HandleWindowOperation(const MouseEvent& event);
+
internal::NativeWidgetDelegate* delegate_;
internal::NativeWidgetView* view_;
@@ -159,8 +167,6 @@ class VIEWS_EXPORT NativeWidgetViews : public internal::NativeWidgetPrivate {
gfx::Rect restored_bounds_;
ui::Transform restored_transform_;
- Widget* hosting_widget_;
-
// See class documentation for Widget in widget.h for a note about ownership.
Widget::InitParams::Ownership ownership_;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index a6ea951..1a085f0 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -1114,6 +1114,10 @@ bool NativeWidgetWin::ConvertPointFromAncestor(
return false;
}
+gfx::Rect NativeWidgetWin::GetWorkAreaBoundsInScreen() const {
+ return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
+}
+
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetWin, MessageLoop::Observer implementation:
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index c433d9b..74ab88e 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -266,6 +266,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
virtual void FocusNativeView(gfx::NativeView native_view) OVERRIDE;
virtual bool ConvertPointFromAncestor(
const Widget* ancestor, gfx::Point* point) const OVERRIDE;
+ virtual gfx::Rect GetWorkAreaBoundsInScreen() const OVERRIDE;
protected:
// Information saved before going into fullscreen mode, used to restore the
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 0f0ecd5..f7f2d86 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -119,7 +119,8 @@ Widget::InitParams::InitParams()
parent(NULL),
parent_widget(NULL),
native_widget(NULL),
- top_level(false) {
+ top_level(false),
+ create_layer(true) {
}
Widget::InitParams::InitParams(Type type)
@@ -139,7 +140,8 @@ Widget::InitParams::InitParams(Type type)
parent(NULL),
parent_widget(NULL),
native_widget(NULL),
- top_level(false) {
+ top_level(false),
+ create_layer(true) {
}
////////////////////////////////////////////////////////////////////////////////
@@ -609,7 +611,7 @@ ThemeProvider* Widget::GetThemeProvider() const {
}
FocusManager* Widget::GetFocusManager() {
- Widget* toplevel_widget = GetTopLevelWidget();
+ const Widget* toplevel_widget = GetTopLevelWidget();
return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
}
@@ -804,6 +806,10 @@ View* Widget::GetChildViewParent() {
return GetContentsView() ? GetContentsView() : GetRootView();
}
+gfx::Rect Widget::GetWorkAreaBoundsInScreen() const {
+ return native_widget_->GetWorkAreaBoundsInScreen();
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget, NativeWidgetDelegate implementation:
diff --git a/views/widget/widget.h b/views/widget/widget.h
index d51dca3..24a21b5 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -159,6 +159,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// The Widget will not construct a default one. Default is NULL.
NativeWidget* native_widget;
bool top_level;
+ // When set NativeWidgetViews will create its own layer.
+ bool create_layer;
};
Widget();
@@ -568,6 +570,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// TYPE_CONTROL and TYPE_TOOLTIP is not considered top level.
bool is_top_level() const { return is_top_level_; }
+ // Returns the bounds of work area in the screen that Widget belongs to.
+ gfx::Rect GetWorkAreaBoundsInScreen() const;
+
// Overridden from NativeWidgetDelegate:
virtual bool IsModal() const OVERRIDE;
virtual bool IsDialogBox() const OVERRIDE;