diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-23 18:52:35 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-23 18:52:35 +0000 |
commit | 8a1cc07176574962b360ff826015c74beecc87d2 (patch) | |
tree | b4c93f0b0667cee474cb4317e2ecb12514a47887 /chrome/browser | |
parent | 2d758a10306f871b80b9584c8a1f080fd455ebdb (diff) | |
download | chromium_src-8a1cc07176574962b360ff826015c74beecc87d2.zip chromium_src-8a1cc07176574962b360ff826015c74beecc87d2.tar.gz chromium_src-8a1cc07176574962b360ff826015c74beecc87d2.tar.bz2 |
Add an option to run Chrome in the views desktop.
- Add a BrowserFrameViews stub.
- Add a NativeTabContentsViewViews stub.
- Allow the omnibox to run in pure-views mode on Windows too.
- Make the RenderWidgetHostViewViews build on Windows.
chrome --use-pure-views --views-desktop runs, shows a browser window, but doesn't really do anything else.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7206055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90242 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
19 files changed, 650 insertions, 285 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 51d2b22..df8317f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -114,6 +114,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/gl/gl_implementation.h" #include "ui/gfx/gl/gl_switches.h" +#include "views/desktop/desktop_window.h" #if defined(USE_LINUX_BREAKPAD) #include "base/linux_util.h" @@ -1379,6 +1380,18 @@ int BrowserMain(const MainFunctionParams& parameters) { RegisterTranslateableItems(); #endif +#if defined(TOOLKIT_VIEWS) + // Launch the views desktop shell window and register it as the default parent + // for all unparented views widgets. + if (parsed_command_line.HasSwitch(switches::kViewsDesktop)) { + views::desktop::DesktopWindow::CreateDesktopWindow(); + ChromeViewsDelegate* chrome_views_delegate = + static_cast<ChromeViewsDelegate*>(views::ViewsDelegate::views_delegate); + chrome_views_delegate->default_parent_view = + views::desktop::DesktopWindow::desktop_window; + } +#endif + BrowserInit browser_init; // On first run, we need to process the predictor preferences before the diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.cc b/chrome/browser/renderer_host/render_widget_host_view_views.cc index 3439b4e..f4c9c42 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_views.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_views.cc @@ -22,42 +22,24 @@ #include "content/common/view_messages.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.h" -#include "ui/base/keycodes/keyboard_code_conversion_gtk.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/x/x11_util.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia.h" -#include "ui/gfx/gtk_native_view_id_manager.h" #include "views/events/event.h" #include "views/ime/input_method.h" -#include "views/widget/native_widget_gtk.h" #include "views/widget/widget.h" static const int kMaxWindowWidth = 4000; static const int kMaxWindowHeight = 4000; -static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; - -// Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp -// -// Match key code of composition keydown event on windows. -// IE sends VK_PROCESSKEY which has value 229; -// -// Please refer to following documents for detals: -// - Virtual-Key Codes -// http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx -// - How the IME System Works -// http://msdn.microsoft.com/en-us/library/cc194848.aspx -// - ImmGetVirtualKey Function -// http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx -static const int kCompositionEventKeyCode = 229; + +// static +const char RenderWidgetHostViewViews::kViewClassName[] = + "browser/renderer_host/RenderWidgetHostViewViews"; using WebKit::WebInputEventFactory; using WebKit::WebMouseWheelEvent; using WebKit::WebTouchEvent; -const char RenderWidgetHostViewViews::kViewClassName[] = - "browser/renderer_host/RenderWidgetHostViewViews"; - namespace { int WebInputEventFlagsFromViewsEvent(const views::Event& event) { @@ -75,56 +57,6 @@ int WebInputEventFlagsFromViewsEvent(const views::Event& event) { return modifiers; } -WebKit::WebTouchPoint::State TouchPointStateFromEvent( - const views::TouchEvent* event) { - switch (event->type()) { - case ui::ET_TOUCH_PRESSED: - return WebKit::WebTouchPoint::StatePressed; - case ui::ET_TOUCH_RELEASED: - return WebKit::WebTouchPoint::StateReleased; - case ui::ET_TOUCH_MOVED: - return WebKit::WebTouchPoint::StateMoved; - case ui::ET_TOUCH_CANCELLED: - return WebKit::WebTouchPoint::StateCancelled; - default: - return WebKit::WebTouchPoint::StateUndefined; - } -} - -WebKit::WebInputEvent::Type TouchEventTypeFromEvent( - const views::TouchEvent* event) { - switch (event->type()) { - case ui::ET_TOUCH_PRESSED: - return WebKit::WebInputEvent::TouchStart; - case ui::ET_TOUCH_RELEASED: - return WebKit::WebInputEvent::TouchEnd; - case ui::ET_TOUCH_MOVED: - return WebKit::WebInputEvent::TouchMove; - case ui::ET_TOUCH_CANCELLED: - return WebKit::WebInputEvent::TouchCancel; - default: - return WebKit::WebInputEvent::Undefined; - } -} - -inline void UpdateTouchParams(const views::TouchEvent& event, - WebKit::WebTouchPoint* tpoint) { - tpoint->radiusX = event.radius_x(); - tpoint->radiusY = event.radius_y(); - tpoint->rotationAngle = event.rotation_angle(); - tpoint->force = event.force(); -} - -void UpdateTouchPointPosition(const views::TouchEvent* event, - const gfx::Point& origin, - WebKit::WebTouchPoint* tpoint) { - tpoint->position.x = event->x(); - tpoint->position.y = event->y(); - - tpoint->screenPosition.x = tpoint->position.x + origin.x(); - tpoint->screenPosition.y = tpoint->position.y + origin.y(); -} - void InitializeWebMouseEventFromViewsEvent(const views::LocatedEvent& event, const gfx::Point& origin, WebKit::WebMouseEvent* wmevent) { @@ -139,12 +71,6 @@ void InitializeWebMouseEventFromViewsEvent(const views::LocatedEvent& event, } // namespace -// static -RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( - RenderWidgetHost* widget) { - return new RenderWidgetHostViewViews(widget); -} - RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) : host_(host), about_to_validate_and_paint_(false), @@ -276,24 +202,13 @@ gfx::Rect RenderWidgetHostViewViews::GetViewBounds() const { return bounds(); } -void RenderWidgetHostViewViews::UpdateCursor(const WebCursor& cursor) { - // Optimize the common case, where the cursor hasn't changed. - // However, we can switch between different pixmaps, so only on the - // non-pixmap branch. - if (current_cursor_.GetCursorType() != GDK_CURSOR_IS_PIXMAP && - current_cursor_.GetCursorType() == cursor.GetCursorType()) { - return; - } - - current_cursor_ = cursor; - ShowCurrentCursor(); -} - void RenderWidgetHostViewViews::SetIsLoading(bool is_loading) { is_loading_ = is_loading; +#if defined(TOOLKIT_USES_GTK) // Only call ShowCurrentCursor() when it will actually change the cursor. if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) ShowCurrentCursor(); +#endif // TOOLKIT_USES_GTK } void RenderWidgetHostViewViews::ImeUpdateTextInputState( @@ -404,16 +319,6 @@ void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); } -void RenderWidgetHostViewViews::CreatePluginContainer( - gfx::PluginWindowHandle id) { - // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); -} - -void RenderWidgetHostViewViews::DestroyPluginContainer( - gfx::PluginWindowHandle id) { - // TODO(anicolao): plugin_container_manager_.DestroyPluginContainer(id); -} - void RenderWidgetHostViewViews::SetVisuallyDeemphasized( const SkColor* color, bool animate) { // TODO(anicolao) @@ -423,37 +328,10 @@ bool RenderWidgetHostViewViews::ContainsNativeView( gfx::NativeView native_view) const { // TODO(port) NOTREACHED() << - "RenderWidgetHostViewViews::ContainsNativeView not implemented."; + "RenderWidgetHostViewViews::ContainsNativeView not implemented."; return false; } -void RenderWidgetHostViewViews::AcceleratedCompositingActivated( - bool activated) { - // TODO(anicolao): figure out if we need something here - if (activated) - NOTIMPLEMENTED(); -} - -gfx::PluginWindowHandle RenderWidgetHostViewViews::GetCompositingSurface() { - GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); - gfx::PluginWindowHandle surface = gfx::kNullPluginWindow; - gfx::NativeViewId view_id = gfx::IdFromNativeView(GetInnerNativeView()); - - if (!manager->GetXIDForId(&surface, view_id)) { - DLOG(ERROR) << "Can't find XID for view id " << view_id; - } - return surface; -} - -gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { - // TODO(sad): Ideally this function should be equivalent to GetNativeView, and - // NativeWidgetGtk-specific function call should not be necessary. - const views::Widget* widget = GetWidget(); - const views::NativeWidget* native = widget ? widget->native_widget() : NULL; - return native ? static_cast<const views::NativeWidgetGtk*>(native)-> - window_contents() : NULL; -} - std::string RenderWidgetHostViewViews::GetClassName() const { return kViewClassName; } @@ -517,110 +395,6 @@ void RenderWidgetHostViewViews::OnMouseExited(const views::MouseEvent& event) { // Already generated synthetically by webkit. } -ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( - const views::TouchEvent& event) { - if (!host_) - return ui::TOUCH_STATUS_UNKNOWN; - - // Update the list of touch points first. - WebKit::WebTouchPoint* point = NULL; - ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; - - switch (event.type()) { - case ui::ET_TOUCH_PRESSED: - // Add a new touch point. - if (touch_event_.touchPointsLength < - WebTouchEvent::touchPointsLengthCap) { - point = &touch_event_.touchPoints[touch_event_.touchPointsLength++]; - point->id = event.identity(); - - if (touch_event_.touchPointsLength == 1) { - // A new touch sequence has started. - status = ui::TOUCH_STATUS_START; - - // We also want the focus. - RequestFocus(); - - // Confirm existing composition text on touch press events, to make - // sure the input caret won't be moved with an ongoing composition - // text. - FinishImeCompositionSession(); - } - } - break; - case ui::ET_TOUCH_RELEASED: - case ui::ET_TOUCH_CANCELLED: - case ui::ET_TOUCH_MOVED: { - // The touch point should have been added to the event from an earlier - // _PRESSED event. So find that. - // At the moment, only a maximum of 4 touch-points are allowed. So a - // simple loop should be sufficient. - for (int i = 0; i < touch_event_.touchPointsLength; ++i) { - point = touch_event_.touchPoints + i; - if (point->id == event.identity()) { - break; - } - point = NULL; - } - break; - } - default: - DLOG(WARNING) << "Unknown touch event " << event.type(); - break; - } - - if (!point) - return ui::TOUCH_STATUS_UNKNOWN; - - if (status != ui::TOUCH_STATUS_START) - status = ui::TOUCH_STATUS_CONTINUE; - - UpdateTouchParams(event, point); - - // Update the location and state of the point. - point->state = TouchPointStateFromEvent(&event); - if (point->state == WebKit::WebTouchPoint::StateMoved) { - // It is possible for badly written touch drivers to emit Move events even - // when the touch location hasn't changed. In such cases, consume the event - // and pretend nothing happened. - if (point->position.x == event.x() && point->position.y == event.y()) { - return status; - } - } - UpdateTouchPointPosition(&event, GetMirroredPosition(), point); - - // Mark the rest of the points as stationary. - for (int i = 0; i < touch_event_.touchPointsLength; ++i) { - WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i; - if (iter != point) { - iter->state = WebKit::WebTouchPoint::StateStationary; - } - } - - // Update the type of the touch event. - touch_event_.type = TouchEventTypeFromEvent(&event); - touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT(); - - // The event and all the touches have been updated. Dispatch. - host_->ForwardTouchEvent(touch_event_); - - // If the touch was released, then remove it from the list of touch points. - if (event.type() == ui::ET_TOUCH_RELEASED) { - --touch_event_.touchPointsLength; - for (int i = point - touch_event_.touchPoints; - i < touch_event_.touchPointsLength; - ++i) { - touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1]; - } - if (touch_event_.touchPointsLength == 0) - status = ui::TOUCH_STATUS_END; - } else if (event.type() == ui::ET_TOUCH_CANCELLED) { - status = ui::TOUCH_STATUS_CANCEL; - } - - return status; -} - bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent& event) { // TODO(suzhe): Support editor key bindings. if (!host_) @@ -807,7 +581,9 @@ void RenderWidgetHostViewViews::OnPaint(gfx::Canvas* canvas) { if (host_->is_accelerated_compositing_active()) return; +#if defined(TOOLKIT_USES_GTK) GdkWindow* window = GetInnerNativeView()->window; +#endif DCHECK(!about_to_validate_and_paint_); // TODO(anicolao): get the damage somehow @@ -825,10 +601,12 @@ void RenderWidgetHostViewViews::OnPaint(gfx::Canvas* canvas) { paint_rect = paint_rect.Intersect(invalid_rect_); if (backing_store) { +#if defined(TOOLKIT_USES_GTK) // Only render the widget if it is attached to a window; there's a short // period where this object isn't attached to a window but hasn't been // Destroy()ed yet and it receives paint messages... if (window) { +#endif if (!visually_deemphasized_) { // In the common case, use XCopyArea. We don't draw more than once, so // we don't need to double buffer. @@ -843,7 +621,9 @@ void RenderWidgetHostViewViews::OnPaint(gfx::Canvas* canvas) { // TODO(sad) NOTIMPLEMENTED(); } +#if defined(TOOLKIT_USES_GTK) } +#endif if (!whiteout_start_time_.is_null()) { base::TimeDelta whiteout_duration = base::TimeTicks::Now() - whiteout_start_time_; @@ -909,15 +689,6 @@ bool RenderWidgetHostViewViews::IsPopup() { return popup_type_ != WebKit::WebPopupTypeNone; } -void RenderWidgetHostViewViews::ShowCurrentCursor() { - // The widget may not have a window. If that's the case, abort mission. This - // is the same issue as that explained above in Paint(). - if (!GetInnerNativeView() || !GetInnerNativeView()->window) - return; - - native_cursor_ = current_cursor_.GetNativeCursor(); -} - WebKit::WebMouseEvent RenderWidgetHostViewViews::WebMouseEventFromViewsEvent( const views::MouseEvent& event) { WebKit::WebMouseEvent wmevent; @@ -950,12 +721,3 @@ void RenderWidgetHostViewViews::FinishImeCompositionSession() { GetInputMethod()->CancelComposition(this); has_composition_text_ = false; } - -// static -RenderWidgetHostView* - RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( - gfx::NativeView widget) { - gpointer user_data = g_object_get_data(G_OBJECT(widget), - kRenderWidgetHostViewKey); - return reinterpret_cast<RenderWidgetHostView*>(user_data); -} diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.h b/chrome/browser/renderer_host/render_widget_host_view_views.h index 78957ec..bee05a1 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_views.h +++ b/chrome/browser/renderer_host/render_widget_host_view_views.h @@ -21,9 +21,11 @@ #include "views/view.h" #include "webkit/glue/webcursor.h" +#if defined(TOUCH_UI) namespace ui { enum TouchStatus; } +#endif class RenderWidgetHost; struct NativeWebKeyboardEvent; @@ -80,12 +82,20 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, virtual void ShowingContextMenu(bool showing) OVERRIDE; virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual void SetBackground(const SkBitmap& background) OVERRIDE; +#if defined(TOOLKIT_USES_GTK) virtual void CreatePluginContainer(gfx::PluginWindowHandle id) OVERRIDE; virtual void DestroyPluginContainer(gfx::PluginWindowHandle id) OVERRIDE; +#endif virtual void SetVisuallyDeemphasized(const SkColor* color, bool animate) OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; +#if defined(TOOLKIT_USES_GTK) virtual void AcceleratedCompositingActivated(bool activated) OVERRIDE; +#endif +#if defined(OS_WIN) + virtual void WillWmDestroy() OVERRIDE; + virtual void ShowCompositorHostWindow(bool show) OVERRIDE; +#endif virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE; // On some systems, there can be two native views, where an outer native view @@ -102,7 +112,9 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; +#if defined(TOUCH_UI) virtual ui::TouchStatus OnTouchEvent(const views::TouchEvent& event) OVERRIDE; +#endif virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; diff --git a/chrome/browser/renderer_host/render_widget_host_view_views_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_views_gtk.cc new file mode 100644 index 0000000..c304664 --- /dev/null +++ b/chrome/browser/renderer_host/render_widget_host_view_views_gtk.cc @@ -0,0 +1,70 @@ +// 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 "chrome/browser/renderer_host/render_widget_host_view_views.h" + +#include "ui/base/keycodes/keyboard_code_conversion_gtk.h" +#include "ui/base/x/x11_util.h" +#include "ui/gfx/gtk_native_view_id_manager.h" +#include "views/widget/native_widget_gtk.h" + +void RenderWidgetHostViewViews::UpdateCursor(const WebCursor& cursor) { + // Optimize the common case, where the cursor hasn't changed. + // However, we can switch between different pixmaps, so only on the + // non-pixmap branch. + if (current_cursor_.GetCursorType() != GDK_CURSOR_IS_PIXMAP && + current_cursor_.GetCursorType() == cursor.GetCursorType()) { + return; + } + + current_cursor_ = cursor; + ShowCurrentCursor(); +} + +void RenderWidgetHostViewViews::CreatePluginContainer( + gfx::PluginWindowHandle id) { + // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); +} + +void RenderWidgetHostViewViews::DestroyPluginContainer( + gfx::PluginWindowHandle id) { + // TODO(anicolao): plugin_container_manager_.DestroyPluginContainer(id); +} + +void RenderWidgetHostViewViews::AcceleratedCompositingActivated( + bool activated) { + // TODO(anicolao): figure out if we need something here + if (activated) + NOTIMPLEMENTED(); +} + +gfx::PluginWindowHandle RenderWidgetHostViewViews::GetCompositingSurface() { + GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); + gfx::PluginWindowHandle surface = gfx::kNullPluginWindow; + gfx::NativeViewId view_id = gfx::IdFromNativeView(GetInnerNativeView()); + + if (!manager->GetXIDForId(&surface, view_id)) { + DLOG(ERROR) << "Can't find XID for view id " << view_id; + } + return surface; +} + +gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { + // TODO(sad): Ideally this function should be equivalent to GetNativeView, and + // NativeWidgetGtk-specific function call should not be necessary. + const views::Widget* widget = GetWidget(); + const views::NativeWidget* native = widget ? widget->native_widget() : NULL; + return native ? static_cast<const views::NativeWidgetGtk*>(native)-> + window_contents() : NULL; +} + +void RenderWidgetHostViewViews::ShowCurrentCursor() { + // The widget may not have a window. If that's the case, abort mission. This + // is the same issue as that explained above in Paint(). + if (!GetInnerNativeView() || !GetInnerNativeView()->window) + return; + + native_cursor_ = current_cursor_.GetNativeCursor(); +} + diff --git a/chrome/browser/renderer_host/render_widget_host_view_views_touch.cc b/chrome/browser/renderer_host/render_widget_host_view_views_touch.cc new file mode 100644 index 0000000..2218a3a --- /dev/null +++ b/chrome/browser/renderer_host/render_widget_host_view_views_touch.cc @@ -0,0 +1,189 @@ +// 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 "chrome/browser/renderer_host/render_widget_host_view_views.h" + +#include "base/logging.h" +#include "content/browser/renderer_host/render_widget_host.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.h" + +static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; + +using WebKit::WebInputEventFactory; +using WebKit::WebTouchEvent; + +namespace { + +WebKit::WebTouchPoint::State TouchPointStateFromEvent( + const views::TouchEvent* event) { + switch (event->type()) { + case ui::ET_TOUCH_PRESSED: + return WebKit::WebTouchPoint::StatePressed; + case ui::ET_TOUCH_RELEASED: + return WebKit::WebTouchPoint::StateReleased; + case ui::ET_TOUCH_MOVED: + return WebKit::WebTouchPoint::StateMoved; + case ui::ET_TOUCH_CANCELLED: + return WebKit::WebTouchPoint::StateCancelled; + default: + return WebKit::WebTouchPoint::StateUndefined; + } +} + +WebKit::WebInputEvent::Type TouchEventTypeFromEvent( + const views::TouchEvent* event) { + switch (event->type()) { + case ui::ET_TOUCH_PRESSED: + return WebKit::WebInputEvent::TouchStart; + case ui::ET_TOUCH_RELEASED: + return WebKit::WebInputEvent::TouchEnd; + case ui::ET_TOUCH_MOVED: + return WebKit::WebInputEvent::TouchMove; + case ui::ET_TOUCH_CANCELLED: + return WebKit::WebInputEvent::TouchCancel; + default: + return WebKit::WebInputEvent::Undefined; + } +} + +inline void UpdateTouchParams(const views::TouchEvent& event, + WebKit::WebTouchPoint* tpoint) { + tpoint->radiusX = event.radius_x(); + tpoint->radiusY = event.radius_y(); + tpoint->rotationAngle = event.rotation_angle(); + tpoint->force = event.force(); +} + +void UpdateTouchPointPosition(const views::TouchEvent* event, + const gfx::Point& origin, + WebKit::WebTouchPoint* tpoint) { + tpoint->position.x = event->x(); + tpoint->position.y = event->y(); + + tpoint->screenPosition.x = tpoint->position.x + origin.x(); + tpoint->screenPosition.y = tpoint->position.y + origin.y(); +} + +} // namespace + +// static +RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( + RenderWidgetHost* widget) { + return new RenderWidgetHostViewViews(widget); +} + +ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( + const views::TouchEvent& event) { + if (!host_) + return ui::TOUCH_STATUS_UNKNOWN; + + // Update the list of touch points first. + WebKit::WebTouchPoint* point = NULL; + ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; + + switch (event.type()) { + case ui::ET_TOUCH_PRESSED: + // Add a new touch point. + if (touch_event_.touchPointsLength < + WebTouchEvent::touchPointsLengthCap) { + point = &touch_event_.touchPoints[touch_event_.touchPointsLength++]; + point->id = event.identity(); + + if (touch_event_.touchPointsLength == 1) { + // A new touch sequence has started. + status = ui::TOUCH_STATUS_START; + + // We also want the focus. + RequestFocus(); + + // Confirm existing composition text on touch press events, to make + // sure the input caret won't be moved with an ongoing composition + // text. + FinishImeCompositionSession(); + } + } + break; + case ui::ET_TOUCH_RELEASED: + case ui::ET_TOUCH_CANCELLED: + case ui::ET_TOUCH_MOVED: { + // The touch point should have been added to the event from an earlier + // _PRESSED event. So find that. + // At the moment, only a maximum of 4 touch-points are allowed. So a + // simple loop should be sufficient. + for (int i = 0; i < touch_event_.touchPointsLength; ++i) { + point = touch_event_.touchPoints + i; + if (point->id == event.identity()) { + break; + } + point = NULL; + } + break; + } + default: + DLOG(WARNING) << "Unknown touch event " << event.type(); + break; + } + + if (!point) + return ui::TOUCH_STATUS_UNKNOWN; + + if (status != ui::TOUCH_STATUS_START) + status = ui::TOUCH_STATUS_CONTINUE; + + UpdateTouchParams(event, point); + + // Update the location and state of the point. + point->state = TouchPointStateFromEvent(&event); + if (point->state == WebKit::WebTouchPoint::StateMoved) { + // It is possible for badly written touch drivers to emit Move events even + // when the touch location hasn't changed. In such cases, consume the event + // and pretend nothing happened. + if (point->position.x == event.x() && point->position.y == event.y()) { + return status; + } + } + UpdateTouchPointPosition(&event, GetMirroredPosition(), point); + + // Mark the rest of the points as stationary. + for (int i = 0; i < touch_event_.touchPointsLength; ++i) { + WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i; + if (iter != point) { + iter->state = WebKit::WebTouchPoint::StateStationary; + } + } + + // Update the type of the touch event. + touch_event_.type = TouchEventTypeFromEvent(&event); + touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT(); + + // The event and all the touches have been updated. Dispatch. + host_->ForwardTouchEvent(touch_event_); + + // If the touch was released, then remove it from the list of touch points. + if (event.type() == ui::ET_TOUCH_RELEASED) { + --touch_event_.touchPointsLength; + for (int i = point - touch_event_.touchPoints; + i < touch_event_.touchPointsLength; + ++i) { + touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1]; + } + if (touch_event_.touchPointsLength == 0) + status = ui::TOUCH_STATUS_END; + } else if (event.type() == ui::ET_TOUCH_CANCELLED) { + status = ui::TOUCH_STATUS_CANCEL; + } + + return status; +} + +// static +RenderWidgetHostView* + RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( + gfx::NativeView widget) { + // TODO(beng): Figure out what to do here for Windows/v.o.v. + gpointer user_data = g_object_get_data(G_OBJECT(widget), + kRenderWidgetHostViewKey); + return reinterpret_cast<RenderWidgetHostView*>(user_data); +} + diff --git a/chrome/browser/renderer_host/render_widget_host_view_views_win.cc b/chrome/browser/renderer_host/render_widget_host_view_views_win.cc new file mode 100644 index 0000000..476420c --- /dev/null +++ b/chrome/browser/renderer_host/render_widget_host_view_views_win.cc @@ -0,0 +1,33 @@ +// 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 "chrome/browser/renderer_host/render_widget_host_view_views.h" + +#include "base/logging.h" + +void RenderWidgetHostViewViews::UpdateCursor(const WebCursor& cursor) { +} + +void RenderWidgetHostViewViews::WillWmDestroy() { + NOTIMPLEMENTED(); +} + +void RenderWidgetHostViewViews::ShowCompositorHostWindow(bool show) { + NOTIMPLEMENTED(); +} + +gfx::PluginWindowHandle RenderWidgetHostViewViews::GetCompositingSurface() { + NOTIMPLEMENTED(); + return NULL; +} + +gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { + NOTIMPLEMENTED(); + // TODO(beng): Figure out what to do here for Windows/v.o.v. + return NULL; +} + +void RenderWidgetHostViewViews::ShowCurrentCursor() { + NOTIMPLEMENTED(); +} diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 1ff06f4..fc28ed1 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -18,6 +18,7 @@ #include "chrome/browser/accessibility/browser_accessibility_state.h" #include "chrome/browser/accessibility/browser_accessibility_win.h" #include "chrome/browser/browser_trial.h" +#include "chrome/browser/renderer_host/render_widget_host_view_views.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" @@ -214,6 +215,8 @@ LRESULT CALLBACK PluginWrapperWindowProc(HWND window, unsigned int message, // static RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( RenderWidgetHost* widget) { + if (views::Widget::IsPureViews()) + return new RenderWidgetHostViewViews(widget); return new RenderWidgetHostViewWin(widget); } @@ -1804,6 +1807,10 @@ void RenderWidgetHostViewWin::ShutdownHost() { RenderWidgetHostView* RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( gfx::NativeView native_view) { + if (views::Widget::IsPureViews()) { + // TODO(beng): Figure out what to do for Windows/v.o.v. + return NULL; + } return ::IsWindow(native_view) ? reinterpret_cast<RenderWidgetHostView*>( ViewProp::GetValue(native_view, kRenderWidgetHostViewKey)) : NULL; diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index c1d6b4d..ab8cf87 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -44,6 +44,9 @@ PrefService* GetPrefsForWindow(const views::Widget* window) { } // namespace +// static +views::View* ChromeViewsDelegate::default_parent_view = NULL; + /////////////////////////////////////////////////////////////////////////////// // ChromeViewsDelegate, views::ViewsDelegate implementation: @@ -52,7 +55,7 @@ ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { } views::View* ChromeViewsDelegate::GetDefaultParentView() { - return NULL; + return default_parent_view; } void ChromeViewsDelegate::SaveWindowPlacement(const views::Widget* window, diff --git a/chrome/browser/ui/views/chrome_views_delegate.h b/chrome/browser/ui/views/chrome_views_delegate.h index 2e67236..f620081 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.h +++ b/chrome/browser/ui/views/chrome_views_delegate.h @@ -14,6 +14,8 @@ class ChromeViewsDelegate : public views::ViewsDelegate { public: + static views::View* default_parent_view; + ChromeViewsDelegate() {} virtual ~ChromeViewsDelegate() {} diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.cc b/chrome/browser/ui/views/frame/browser_frame_gtk.cc index 5513a98..dd19ae8 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.cc +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.cc @@ -10,10 +10,12 @@ #include "chrome/browser/themes/theme_service_factory.h" #include "chrome/browser/ui/status_bubble.h" #include "chrome/browser/ui/views/frame/app_panel_browser_frame_view.h" +#include "chrome/browser/ui/views/frame/browser_frame_views.h" #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "ui/gfx/font.h" #include "views/widget/root_view.h" +#include "views/widget/widget.h" #include "views/window/hit_test.h" // static @@ -89,6 +91,8 @@ gboolean BrowserFrameGtk::OnConfigureEvent(GtkWidget* widget, NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( BrowserFrame* browser_frame, BrowserView* browser_view) { + if (views::Widget::IsPureViews()) + return new BrowserFrameViews(browser_frame, browser_view); return new BrowserFrameGtk(browser_frame, browser_view); } diff --git a/chrome/browser/ui/views/frame/browser_frame_views.cc b/chrome/browser/ui/views/frame/browser_frame_views.cc new file mode 100644 index 0000000..8cee9ba --- /dev/null +++ b/chrome/browser/ui/views/frame/browser_frame_views.cc @@ -0,0 +1,37 @@ +// 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 "chrome/browser/ui/views/frame/browser_frame_views.h" + +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameViews, public: + +BrowserFrameViews::BrowserFrameViews(BrowserFrame* browser_frame, + BrowserView* browser_view) + : views::NativeWidgetViews(browser_frame), + browser_view_(browser_view), + browser_frame_(browser_frame) { +} + +BrowserFrameViews::~BrowserFrameViews() { +} + +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameViews, NativeBrowserFrame implementation: + +views::NativeWidget* BrowserFrameViews::AsNativeWidget() { + return this; +} + +const views::NativeWidget* BrowserFrameViews::AsNativeWidget() const { + return this; +} + +int BrowserFrameViews::GetMinimizeButtonOffset() const { + return 0; +} + +void BrowserFrameViews::TabStripDisplayModeChanged() { +} + diff --git a/chrome/browser/ui/views/frame/browser_frame_views.h b/chrome/browser/ui/views/frame/browser_frame_views.h new file mode 100644 index 0000000..bf9dc79 --- /dev/null +++ b/chrome/browser/ui/views/frame/browser_frame_views.h @@ -0,0 +1,46 @@ +// 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 CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_VIEWS_H_ +#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_VIEWS_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/ui/views/frame/browser_frame.h" +#include "chrome/browser/ui/views/frame/native_browser_frame.h" +#include "views/widget/native_widget_views.h" + +class BrowserView; + +//////////////////////////////////////////////////////////////////////////////// +// BrowserFrameViews +// +// BrowserFrameViews is a NativeWidgetViews subclass that provides the window +// frame for the Chrome browser window. +// +class BrowserFrameViews : public views::NativeWidgetViews, + public NativeBrowserFrame { + public: + BrowserFrameViews(BrowserFrame* browser_frame, BrowserView* browser_view); + virtual ~BrowserFrameViews(); + + BrowserView* browser_view() const { return browser_view_; } + + protected: + // Overridden from NativeBrowserFrame: + virtual views::NativeWidget* AsNativeWidget() OVERRIDE; + virtual const views::NativeWidget* AsNativeWidget() const OVERRIDE; + virtual int GetMinimizeButtonOffset() const OVERRIDE; + virtual void TabStripDisplayModeChanged() OVERRIDE; + + private: + // The BrowserView is our ClientView. This is a pointer to it. + BrowserView* browser_view_; + + BrowserFrame* browser_frame_; + + DISALLOW_COPY_AND_ASSIGN(BrowserFrameViews); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_FRAME_VIEWS_H_ diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 1d2d4f5..e3f5cdc 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -11,6 +11,7 @@ #include "chrome/browser/accessibility/browser_accessibility_state.h" #include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/views/frame/browser_frame_views.h" #include "chrome/browser/ui/views/frame/browser_view.h" #include "grit/theme_resources.h" #include "ui/base/theme_provider.h" @@ -216,6 +217,8 @@ const gfx::Font& BrowserFrame::GetTitleFont() { NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( BrowserFrame* browser_frame, BrowserView* browser_view) { + if (views::Widget::IsPureViews()) + return new BrowserFrameViews(browser_frame, browser_view); return new BrowserFrameWin(browser_frame, browser_view); } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 47eb770..8fcde88 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -35,6 +35,7 @@ #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" #include "chrome/browser/ui/views/location_bar/star_view.h" +#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/browser/renderer_host/render_widget_host_view.h" @@ -51,6 +52,7 @@ #include "ui/gfx/color_utils.h" #include "ui/gfx/skia_util.h" #include "views/controls/label.h" +#include "views/controls/textfield/native_textfield_views.h" #include "views/drag_utils.h" #if defined(OS_WIN) @@ -171,9 +173,17 @@ void LocationBarView::Init() { // URL edit field. // View container for URL edit field. #if defined(OS_WIN) - location_entry_.reset(new OmniboxViewWin(font_, this, model_, this, - GetWidget()->GetNativeView(), profile_, browser_->command_updater(), - mode_ == POPUP, this)); + if (UseViewsOmnibox()) { + OmniboxViewViews* omnibox_view = + new OmniboxViewViews(this, model_, profile_, + browser_->command_updater(), mode_ == POPUP, this); + omnibox_view->Init(); + location_entry_.reset(omnibox_view); + } else { + location_entry_.reset(new OmniboxViewWin(font_, this, model_, this, + GetWidget()->GetNativeView(), profile_, browser_->command_updater(), + mode_ == POPUP, this)); + } #else location_entry_.reset(OmniboxViewGtk::Create(this, model_, profile_, browser_->command_updater(), mode_ == POPUP, this)); @@ -421,7 +431,10 @@ void LocationBarView::SetInstantSuggestion(const string16& text, GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); suggested_text_view_->SetText(UTF16ToWide(text)); - suggested_text_view_->SetFont(location_entry_->GetFont()); + if (UseViewsOmnibox()) + NOTIMPLEMENTED(); + else + suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); AddChildView(suggested_text_view_); } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) { suggested_text_view_->SetText(UTF16ToWide(text)); @@ -533,12 +546,17 @@ void LocationBarView::Layout() { } #if defined(OS_WIN) - RECT formatting_rect; - location_entry_->GetRect(&formatting_rect); - RECT edit_bounds; - location_entry_->GetClientRect(&edit_bounds); - int max_edit_width = entry_width - formatting_rect.left - - (edit_bounds.right - formatting_rect.right); + int max_edit_width = entry_width; + if (UseViewsOmnibox()) { + NOTIMPLEMENTED(); + } else { + RECT formatting_rect; + GetOmniboxViewWin()->GetRect(&formatting_rect); + RECT edit_bounds; + GetOmniboxViewWin()->GetClientRect(&edit_bounds); + max_edit_width = entry_width - formatting_rect.left - + (edit_bounds.right - formatting_rect.right); + } #else int max_edit_width = entry_width; #endif @@ -657,22 +675,27 @@ void LocationBarView::Layout() { // keyword hints and suggested text is minimal and we're not confident this // is the right approach for suggested text. if (suggested_text_view_) { - // TODO(sky): need to layout when the user changes caret position. - int suggested_text_width = suggested_text_view_->GetPreferredSize().width(); - int vis_text_width = location_entry_->WidthOfTextAfterCursor(); - if (vis_text_width + suggested_text_width > entry_width) { - // Hide the suggested text if the user has scrolled or we can't fit all - // the suggested text. - suggested_text_view_->SetBounds(0, 0, 0, 0); + if (UseViewsOmnibox()) { + NOTIMPLEMENTED(); } else { - int location_needed_width = location_entry_->TextWidth(); - location_bounds.set_width(std::min(location_needed_width, - entry_width - suggested_text_width)); - // TODO(sky): figure out why this needs the -1. - suggested_text_view_->SetBounds(location_bounds.right() - 1, - location_bounds.y(), - suggested_text_width, - location_bounds.height()); + // TODO(sky): need to layout when the user changes caret position. + int suggested_text_width = + suggested_text_view_->GetPreferredSize().width(); + int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); + if (vis_text_width + suggested_text_width > entry_width) { + // Hide the suggested text if the user has scrolled or we can't fit all + // the suggested text. + suggested_text_view_->SetBounds(0, 0, 0, 0); + } else { + int location_needed_width = location_entry_->TextWidth(); + location_bounds.set_width(std::min(location_needed_width, + entry_width - suggested_text_width)); + // TODO(sky): figure out why this needs the -1. + suggested_text_view_->SetBounds(location_bounds.right() - 1, + location_bounds.y(), + suggested_text_width, + location_bounds.height()); + } } } #endif @@ -778,7 +801,10 @@ void LocationBarView::OnMouseReleased(const views::MouseEvent& event) { } void LocationBarView::OnMouseCaptureLost() { - location_entry_->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); + if (UseViewsOmnibox()) + NOTIMPLEMENTED(); + else + GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); } #endif @@ -971,7 +997,10 @@ void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { UINT flags = event.GetWindowsFlags(); gfx::Point screen_point(event.location()); ConvertPointToScreen(this, &screen_point); - location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); + if (UseViewsOmnibox()) + NOTIMPLEMENTED(); + else + GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); } #endif @@ -1003,6 +1032,7 @@ std::string LocationBarView::GetClassName() const { bool LocationBarView::SkipDefaultKeyEventProcessing( const views::KeyEvent& event) { #if defined(OS_WIN) + bool views_omnibox = UseViewsOmnibox(); if (views::FocusManager::IsTabTraversalKeyEvent(event)) { if (HasValidSuggestText()) { // Return true so that the edit sees the tab and commits the suggestion. @@ -1014,7 +1044,7 @@ bool LocationBarView::SkipDefaultKeyEventProcessing( } // If the caret is not at the end, then tab moves the caret to the end. - if (!location_entry_->IsCaretAtEnd()) + if (!views_omnibox && !GetOmniboxViewWin()->IsCaretAtEnd()) return true; // Tab while showing instant commits instant immediately. @@ -1024,7 +1054,10 @@ bool LocationBarView::SkipDefaultKeyEventProcessing( return true; } - return location_entry_->SkipDefaultKeyEventProcessing(event); + if (!views_omnibox) + return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); + NOTIMPLEMENTED(); + return false; #else // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in // src/views/focus/focus_manager.cc for details. @@ -1221,4 +1254,14 @@ bool LocationBarView::HasValidSuggestText() const { return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && !suggested_text_view_->GetText().empty(); } + +OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { + CHECK(!UseViewsOmnibox()); + return static_cast<OmniboxViewWin*>(location_entry_.get()); +} + +bool LocationBarView::UseViewsOmnibox() { + return views::Widget::IsPureViews() || + views::NativeTextfieldViews::IsTextfieldViewsEnabled(); +} #endif diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h index fa38560..d27ce7a 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.h +++ b/chrome/browser/ui/views/location_bar/location_bar_view.h @@ -330,6 +330,14 @@ class LocationBarView : public LocationBar, // Returns true if the suggest text is valid. bool HasValidSuggestText() const; + + // Returns |location_entry_| cast to OmniboxViewWin, or NULL if + // |location_entry_| is of a different type. + OmniboxViewWin* GetOmniboxViewWin(); + + // Returns true if the views-based omnibox should be used. When false, + // |location_entry_| can be cast to OmniboxViewWin. + static bool UseViewsOmnibox(); #endif // Helper to show the first run info bubble. @@ -339,11 +347,7 @@ class LocationBarView : public LocationBar, Profile* profile_; // The Autocomplete Edit field. -#if defined(OS_WIN) - scoped_ptr<OmniboxViewWin> location_entry_; -#else scoped_ptr<OmniboxView> location_entry_; -#endif // The Browser object that corresponds to this View. Browser* browser_; diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc index dd8fe8c..0c2d89e 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_gtk.cc @@ -10,6 +10,7 @@ #include "chrome/browser/ui/gtk/constrained_window_gtk.h" #include "chrome/browser/ui/gtk/tab_contents_drag_source.h" #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" @@ -261,6 +262,8 @@ void NativeTabContentsViewGtk::PositionConstrainedWindows( // static NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( internal::NativeTabContentsViewDelegate* delegate) { + if (views::Widget::IsPureViews()) + return new NativeTabContentsViewViews(delegate); return new NativeTabContentsViewGtk(delegate); } diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc new file mode 100644 index 0000000..c309922 --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc @@ -0,0 +1,88 @@ +// 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 "chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h" + +#include "chrome/browser/renderer_host/render_widget_host_view_views.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/tab_contents/tab_contents_view.h" +#include "views/widget/widget.h" + +// TODO(beng): HiddenTabHostWindow?? + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewViews, public: + +NativeTabContentsViewViews::NativeTabContentsViewViews( + internal::NativeTabContentsViewDelegate* delegate) + : views::NativeWidgetViews(delegate->AsNativeWidgetDelegate()), + delegate_(delegate) { +} + +NativeTabContentsViewViews::~NativeTabContentsViewViews() { + CloseNow(); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsViewViews, NativeTabContentsView implementation: + +void NativeTabContentsViewViews::InitNativeTabContentsView() { + views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); + params.native_widget = this; + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + GetWidget()->Init(params); +} + +void NativeTabContentsViewViews::Unparent() { + // Note that we do not DCHECK on focus_manager_ as it may be NULL when used + // with an external tab container. + views::Widget::ReparentNativeView(GetNativeView(), NULL); +} + +RenderWidgetHostView* NativeTabContentsViewViews::CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) { + RenderWidgetHostViewViews* view = + new RenderWidgetHostViewViews(render_widget_host); + GetWidget()->SetContentsView(view); + view->Show(); + view->InitAsChild(); + // TODO(anicolao): implement drag'n'drop hooks if needed + return view; +} + +gfx::NativeWindow NativeTabContentsViewViews::GetTopLevelNativeWindow() const { + NOTIMPLEMENTED(); + return NULL; +} + +void NativeTabContentsViewViews::SetPageTitle(const std::wstring& title) { + SetWindowTitle(title); +} + +void NativeTabContentsViewViews::StartDragging( + const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) { + NOTIMPLEMENTED(); +} + +void NativeTabContentsViewViews::CancelDrag() { + NOTIMPLEMENTED(); +} + +bool NativeTabContentsViewViews::IsDoingDrag() const { + NOTIMPLEMENTED(); + return false; +} + +void NativeTabContentsViewViews::SetDragCursor( + WebKit::WebDragOperation operation) { + NOTIMPLEMENTED(); +} + +views::NativeWidget* NativeTabContentsViewViews::AsNativeWidget() { + return this; +} diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h new file mode 100644 index 0000000..feacb03 --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h @@ -0,0 +1,43 @@ +// 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 CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_VIEWS_H_ +#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_VIEWS_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view.h" +#include "views/widget/native_widget_views.h" + +class TabContents; + +class NativeTabContentsViewViews : public views::NativeWidgetViews, + public NativeTabContentsView { + public: + explicit NativeTabContentsViewViews( + internal::NativeTabContentsViewDelegate* delegate); + virtual ~NativeTabContentsViewViews(); + + private: + // Overridden from NativeTabContentsView: + virtual void InitNativeTabContentsView() OVERRIDE; + virtual void Unparent() OVERRIDE; + virtual RenderWidgetHostView* CreateRenderWidgetHostView( + RenderWidgetHost* render_widget_host) OVERRIDE; + virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; + virtual void SetPageTitle(const std::wstring& title) OVERRIDE; + virtual void StartDragging(const WebDropData& drop_data, + WebKit::WebDragOperationsMask ops, + const SkBitmap& image, + const gfx::Point& image_offset) OVERRIDE; + virtual void CancelDrag() OVERRIDE; + virtual bool IsDoingDrag() const OVERRIDE; + virtual void SetDragCursor(WebKit::WebDragOperation operation) OVERRIDE; + virtual views::NativeWidget* AsNativeWidget() OVERRIDE; + + internal::NativeTabContentsViewDelegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(NativeTabContentsViewViews); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_VIEW_VIEWS_H_ diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc index b0f91c6..a1550c0 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_win.cc @@ -7,6 +7,7 @@ #include "chrome/browser/renderer_host/render_widget_host_view_win.h" #include "chrome/browser/tab_contents/web_drop_target_win.h" #include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_delegate.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_drag_win.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" @@ -341,5 +342,7 @@ bool NativeTabContentsViewWin::ScrollZoom(int scroll_type) { // static NativeTabContentsView* NativeTabContentsView::CreateNativeTabContentsView( internal::NativeTabContentsViewDelegate* delegate) { + if (views::Widget::IsPureViews()) + return new NativeTabContentsViewViews(delegate); return new NativeTabContentsViewWin(delegate); } |