summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 16:39:34 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-07 16:39:34 +0000
commit9ad527c67d676d639164988a5785449830e5ba56 (patch)
treea130d9b594ff165bf7272b52eb4ac5bf1ccd36fd
parentf95dc3ea9e3ee69c4e7d0155ce42a126626f4925 (diff)
downloadchromium_src-9ad527c67d676d639164988a5785449830e5ba56.zip
chromium_src-9ad527c67d676d639164988a5785449830e5ba56.tar.gz
chromium_src-9ad527c67d676d639164988a5785449830e5ba56.tar.bz2
Switch chrome to use TabContentsViewWin. The goal is to eventually have all TabContentsView implementations in content, since a lot of classes that they would depend on shouldn't be exposed to embedders.
(for others reading: Ben said once this is done TabContentsViewAura will be created and we can remove TabContentsViewViews). BUG=98716 Review URL: https://chromiumcodereview.appspot.com/9600004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125396 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/DEPS1
-rw-r--r--chrome/browser/chrome_content_browser_client.cc12
-rw-r--r--chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.cc163
-rw-r--r--chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h65
-rw-r--r--chrome/browser/ui/sad_tab_helper.cc3
-rw-r--r--chrome/browser/ui/views/constrained_window_views.cc1
-rw-r--r--chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc8
-rw-r--r--chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h3
-rw-r--r--chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc2
-rw-r--r--chrome/chrome_browser.gypi25
-rw-r--r--content/browser/tab_contents/tab_contents_view_win.cc75
-rw-r--r--content/browser/tab_contents/tab_contents_view_win.h28
-rw-r--r--content/content_browser.gypi5
-rw-r--r--content/content_shell.gypi2
-rw-r--r--content/public/browser/web_contents_view_win_delegate.h43
-rw-r--r--content/shell/shell_content_browser_client.cc2
-rw-r--r--content/shell/shell_win.cc6
17 files changed, 388 insertions, 56 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS
index 9c9e642..e3e0253 100644
--- a/chrome/browser/DEPS
+++ b/chrome/browser/DEPS
@@ -59,6 +59,7 @@ include_rules = [
"+content/browser/renderer_host/resource_request_details.h",
"+content/browser/renderer_host/test_render_view_host.h",
"+content/browser/tab_contents/provisional_load_details.h",
+ "+content/browser/tab_contents/tab_contents_view_win.h",
"+content/browser/tab_contents/tab_contents_view_gtk.h",
"+content/browser/tab_contents/tab_contents_view_helper.h",
"+content/browser/tab_contents/test_tab_contents.h",
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc
index 2f58b57..af97c8c 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -92,6 +92,8 @@
#if defined(OS_WIN)
#include "chrome/browser/chrome_browser_main_win.h"
+#include "chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h"
+#include "content/browser/tab_contents/tab_contents_view_win.h"
#elif defined(OS_MACOSX)
#include "chrome/browser/chrome_browser_main_mac.h"
#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
@@ -344,7 +346,15 @@ content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
WebContents* web_contents) {
-#if defined(TOOLKIT_VIEWS)
+#if defined(OS_WIN) && !defined(USE_AURA)
+ // TODO(jam): turn on by default.
+ if (false) {
+ return new TabContentsViewWin(
+ web_contents, new ChromeWebContentsViewWinDelegate(web_contents));
+ } else {
+ return new TabContentsViewViews(web_contents);
+ }
+#elif defined(TOOLKIT_VIEWS)
return new TabContentsViewViews(web_contents);
#elif defined(TOOLKIT_USES_GTK)
return new content::TabContentsViewGtk(web_contents,
diff --git a/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.cc b/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.cc
new file mode 100644
index 0000000..03cdf95
--- /dev/null
+++ b/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2012 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/tab_contents/chrome_web_contents_view_win_delegate.h"
+
+#include "chrome/browser/browser_shutdown.h"
+#include "chrome/browser/tab_contents/web_drag_bookmark_handler_win.h"
+#include "chrome/browser/ui/constrained_window_tab_helper.h"
+#include "chrome/browser/ui/sad_tab_helper.h"
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+#include "chrome/browser/ui/views/constrained_window_views.h"
+#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "ui/views/focus/focus_manager.h"
+#include "ui/views/focus/view_storage.h"
+#include "ui/views/widget/widget.h"
+
+ChromeWebContentsViewWinDelegate::ChromeWebContentsViewWinDelegate(
+ content::WebContents* web_contents)
+ : web_contents_(web_contents) {
+ last_focused_view_storage_id_ =
+ views::ViewStorage::GetInstance()->CreateStorageID();
+}
+
+ChromeWebContentsViewWinDelegate::~ChromeWebContentsViewWinDelegate() {
+ // Makes sure to remove any stored view we may still have in the ViewStorage.
+ //
+ // It is possible the view went away before us, so we only do this if the
+ // view is registered.
+ views::ViewStorage* view_storage = views::ViewStorage::GetInstance();
+ if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
+ view_storage->RemoveView(last_focused_view_storage_id_);
+
+}
+
+content::WebDragDestDelegate*
+ ChromeWebContentsViewWinDelegate::GetDragDestDelegate() {
+ // We install a chrome specific handler to intercept bookmark drags for the
+ // bookmark manager/extension API.
+ bookmark_handler_.reset(new WebDragBookmarkHandlerWin);
+ return bookmark_handler_.get();
+}
+
+bool ChromeWebContentsViewWinDelegate::Focus() {
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(web_contents_);
+ if (wrapper) {
+ views::Widget* sad_tab = wrapper->sad_tab_helper()->sad_tab();
+ if (sad_tab) {
+ sad_tab->GetContentsView()->RequestFocus();
+ return true;
+ }
+
+ // TODO(erg): TabContents used to own constrained windows, which is why
+ // this is here. Eventually this should be ported to a containing view
+ // specializing in constrained window management.
+ ConstrainedWindowTabHelper* helper =
+ wrapper->constrained_window_tab_helper();
+ if (helper->constrained_window_count() > 0) {
+ ConstrainedWindow* window = *helper->constrained_window_begin();
+ DCHECK(window);
+ window->FocusConstrainedWindow();
+ return true;
+ }
+ }
+ return false;
+}
+
+void ChromeWebContentsViewWinDelegate::TakeFocus(bool reverse) {
+ GetFocusManager()->AdvanceFocus(reverse);
+}
+
+void ChromeWebContentsViewWinDelegate::StoreFocus() {
+ views::ViewStorage* view_storage = views::ViewStorage::GetInstance();
+
+ if (view_storage->RetrieveView(last_focused_view_storage_id_) != NULL)
+ view_storage->RemoveView(last_focused_view_storage_id_);
+
+ views::View* focused_view = GetFocusManager()->GetFocusedView();
+ if (focused_view)
+ view_storage->StoreView(last_focused_view_storage_id_, focused_view);
+}
+
+void ChromeWebContentsViewWinDelegate::RestoreFocus() {
+ views::ViewStorage* view_storage = views::ViewStorage::GetInstance();
+ views::View* last_focused_view =
+ view_storage->RetrieveView(last_focused_view_storage_id_);
+
+ if (!last_focused_view) {
+ SetInitialFocus();
+ } else {
+ if (last_focused_view->IsFocusable() &&
+ GetFocusManager()->ContainsView(last_focused_view)) {
+ last_focused_view->RequestFocus();
+ } else {
+ // The focused view may not belong to the same window hierarchy (e.g.
+ // if the location bar was focused and the tab is dragged out), or it may
+ // no longer be focusable (e.g. if the location bar was focused and then
+ // we switched to fullscreen mode). In that case we default to the
+ // default focus.
+ SetInitialFocus();
+ }
+ view_storage->RemoveView(last_focused_view_storage_id_);
+ }
+}
+
+void ChromeWebContentsViewWinDelegate::ShowContextMenu(
+ const content::ContextMenuParams& params) {
+ context_menu_.reset(new RenderViewContextMenuViews(web_contents_, params));
+ context_menu_->Init();
+
+ // Don't show empty menus.
+ if (context_menu_->menu_model().GetItemCount() == 0)
+ return;
+
+ gfx::Point screen_point(params.x, params.y);
+
+ POINT temp = screen_point.ToPOINT();
+ ClientToScreen(web_contents_->GetView()->GetNativeView(), &temp);
+ screen_point = temp;
+
+ // Enable recursive tasks on the message loop so we can get updates while
+ // the context menu is being displayed.
+ MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
+ context_menu_->RunMenuAt(
+ GetTopLevelWidget(), screen_point.x(), screen_point.y());
+}
+
+void ChromeWebContentsViewWinDelegate::SizeChanged(const gfx::Size& size) {
+ TabContentsWrapper* wrapper =
+ TabContentsWrapper::GetCurrentWrapperForContents(web_contents_);
+ if (!wrapper)
+ return;
+ views::Widget* sad_tab = wrapper->sad_tab_helper()->sad_tab();
+ if (sad_tab)
+ sad_tab->SetBounds(gfx::Rect(size));
+}
+
+views::Widget* ChromeWebContentsViewWinDelegate::GetTopLevelWidget() {
+ HWND top_level_window = web_contents_->GetView()->GetTopLevelNativeWindow();
+ if (!top_level_window)
+ return NULL;
+ return views::Widget::GetWidgetForNativeWindow(top_level_window);
+}
+
+views::FocusManager*
+ ChromeWebContentsViewWinDelegate::GetFocusManager() {
+ views::Widget* toplevel_widget = GetTopLevelWidget();
+ return toplevel_widget ? toplevel_widget->GetFocusManager() : NULL;
+}
+
+void ChromeWebContentsViewWinDelegate::SetInitialFocus() {
+ if (web_contents_->FocusLocationBarByDefault()) {
+ web_contents_->SetFocusToLocationBar(false);
+ } else {
+ web_contents_->GetView()->Focus();
+ }
+}
diff --git a/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h b/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h
new file mode 100644
index 0000000..fc341f8
--- /dev/null
+++ b/chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 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_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
+#define CHROME_BROWSER_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/web_contents_view_win_delegate.h"
+
+class ConstrainedWindowViews;
+class RenderViewContextMenuViews;
+class WebDragBookmarkHandlerWin;
+
+namespace content {
+class WebContents;
+}
+
+namespace views {
+class FocusManager;
+class Widget;
+}
+
+// A chrome specific class that extends TabContentsViewWin with features like
+// constrained windows, which live in chrome.
+class ChromeWebContentsViewWinDelegate
+ : public content::WebContentsViewWinDelegate {
+ public:
+ explicit ChromeWebContentsViewWinDelegate(content::WebContents* web_contents);
+ virtual ~ChromeWebContentsViewWinDelegate();
+
+ // Overridden from WebContentsViewWinDelegate:
+ virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE;
+ virtual void StoreFocus() OVERRIDE;
+ virtual void RestoreFocus() OVERRIDE;
+ virtual bool Focus() OVERRIDE;
+ virtual void TakeFocus(bool reverse) OVERRIDE;
+ virtual void ShowContextMenu(
+ const content::ContextMenuParams& params) OVERRIDE;
+ virtual void SizeChanged(const gfx::Size& size) OVERRIDE;
+
+ private:
+ views::Widget* GetTopLevelWidget();
+ views::FocusManager* GetFocusManager();
+ void SetInitialFocus();
+
+ // The id used in the ViewStorage to store the last focused view.
+ int last_focused_view_storage_id_;
+
+ // The context menu is reset every time we show it, but we keep a pointer to
+ // between uses so that it won't go out of scope before we're done with it.
+ scoped_ptr<RenderViewContextMenuViews> context_menu_;
+
+ // The chrome specific delegate that receives events from WebDragDest.
+ scoped_ptr<WebDragBookmarkHandlerWin> bookmark_handler_;
+
+ content::WebContents* web_contents_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChromeWebContentsViewWinDelegate);
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_CHROME_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
diff --git a/chrome/browser/ui/sad_tab_helper.cc b/chrome/browser/ui/sad_tab_helper.cc
index e55f4c7..adec97f 100644
--- a/chrome/browser/ui/sad_tab_helper.cc
+++ b/chrome/browser/ui/sad_tab_helper.cc
@@ -88,8 +88,7 @@ void SadTabHelper::InstallSadTab(base::TerminationStatus status) {
// It is not possible to create a native_widget_win that has no parent in
// and later re-parent it.
// TODO(avi): This is a cheat. Can this be made cleaner?
- sad_tab_params.parent_widget = views::Widget::GetWidgetForNativeView(
- web_contents()->GetView()->GetNativeView());
+ sad_tab_params.parent = web_contents()->GetView()->GetNativeView();
sad_tab_params.ownership =
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
sad_tab_.reset(new views::Widget);
diff --git a/chrome/browser/ui/views/constrained_window_views.cc b/chrome/browser/ui/views/constrained_window_views.cc
index e8d9ad8..50863f1 100644
--- a/chrome/browser/ui/views/constrained_window_views.cc
+++ b/chrome/browser/ui/views/constrained_window_views.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
-#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/web_contents.h"
diff --git a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
index 93bb5a4..27de1d9 100644
--- a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
+++ b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.cc
@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
@@ -33,10 +32,9 @@ RenderViewContextMenuViews::RenderViewContextMenuViews(
RenderViewContextMenuViews::~RenderViewContextMenuViews() {
}
-void RenderViewContextMenuViews::RunMenuAt(int x, int y) {
- TabContentsViewViews* tab =
- static_cast<TabContentsViewViews*>(source_web_contents_->GetView());
- views::Widget* parent = tab->GetTopLevelWidget();
+void RenderViewContextMenuViews::RunMenuAt(views::Widget* parent,
+ int x,
+ int y) {
if (menu_runner_->RunMenuAt(parent, NULL,
gfx::Rect(gfx::Point(x, y), gfx::Size()),
views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) ==
diff --git a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h
index 1151659..001b5cd 100644
--- a/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h
+++ b/chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h
@@ -15,6 +15,7 @@ namespace views {
class MenuItemView;
class MenuModelAdapter;
class MenuRunner;
+class Widget;
} // namespace views
class RenderViewContextMenuViews : public RenderViewContextMenu {
@@ -24,7 +25,7 @@ class RenderViewContextMenuViews : public RenderViewContextMenu {
virtual ~RenderViewContextMenuViews();
- void RunMenuAt(int x, int y);
+ void RunMenuAt(views::Widget* parent, int x, int y);
#if defined(OS_WIN)
// Set this menu to show for an external tab contents. This
diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
index 853068e..be35b1f 100644
--- a/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
+++ b/chrome/browser/ui/views/tab_contents/tab_contents_view_views.cc
@@ -328,7 +328,7 @@ void TabContentsViewViews::ShowContextMenu(
// Enable recursive tasks on the message loop so we can get updates while
// the context menu is being displayed.
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
- context_menu_->RunMenuAt(screen_point.x(), screen_point.y());
+ context_menu_->RunMenuAt(GetTopLevelWidget(), screen_point.x(), screen_point.y());
}
void TabContentsViewViews::ShowPopupMenu(const gfx::Rect& bounds,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 67f2c4d..aa1bcbd 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1886,7 +1886,7 @@
'browser/password_manager_delegate_impl.cc',
'browser/password_manager_delegate_impl.h',
'browser/platform_util.h',
- 'browser/platform_util_android.cc',
+ 'browser/platform_util_android.cc',
'browser/platform_util_aura.cc',
'browser/platform_util_chromeos.cc',
'browser/platform_util_common_linux.cc',
@@ -2517,6 +2517,8 @@
'browser/tab_contents/chrome_web_contents_view_gtk_delegate.h',
'browser/tab_contents/chrome_web_contents_view_mac_delegate.h',
'browser/tab_contents/chrome_web_contents_view_mac_delegate.mm',
+ 'browser/tab_contents/chrome_web_contents_view_win_delegate.cc',
+ 'browser/tab_contents/chrome_web_contents_view_win_delegate.h',
'browser/tab_contents/confirm_infobar_delegate.cc',
'browser/tab_contents/confirm_infobar_delegate.h',
'browser/tab_contents/insecure_content_infobar_delegate.cc',
@@ -4589,6 +4591,8 @@
['exclude', '^browser/google/google_update.h'],
['exclude', '^browser/hang_monitor/'],
['exclude', '^browser/renderer_host/render_widget_host_view_views*'],
+ ['exclude', '^browser/tab_contents/chrome_web_contents_view_win_delegate.cc'],
+ ['exclude', '^browser/tab_contents/chrome_web_contents_view_win_delegate.h'],
['exclude', '^browser/ui/panels/auto_hiding_desktop_bar_win.cc'],
['exclude', '^browser/ui/tabs/dock_info_win.cc'],
['exclude', '^browser/ui/views/about_ipc_dialog.cc'],
@@ -4752,13 +4756,13 @@
}],
],
}, {
- 'sources!': [
- # The rules only catch files that start or end with gtk, but these
- # files would be incorrectly named if we forced the gtk at the end.
- 'browser/tab_contents/chrome_web_contents_view_gtk_delegate.cc',
- 'browser/tab_contents/chrome_web_contents_view_gtk_delegate.h',
- ],
- }],
+ 'sources!': [
+ # The rules only catch files that start or end with gtk, but these
+ # files would be incorrectly named if we forced the gtk at the end.
+ 'browser/tab_contents/chrome_web_contents_view_gtk_delegate.cc',
+ 'browser/tab_contents/chrome_web_contents_view_gtk_delegate.h',
+ ],
+ }],
['input_speech==0', {
'sources/': [
['exclude', '^browser/speech/'],
@@ -5017,6 +5021,11 @@
# Exclude try chrome dialog.
['exclude', '^browser/first_run/try_chrome_dialog_view.cc'],
['exclude', '^browser/first_run/try_chrome_dialog_view.h'],
+
+ # The rules only catch files that start or end with win, but these
+ # files would be incorrectly named if we forced the win at the end.
+ ['exclude', '^browser/tab_contents/chrome_web_contents_view_win_delegate.cc'],
+ ['exclude', '^browser/tab_contents/chrome_web_contents_view_win_delegate.h'],
],
'conditions': [
['use_aura==1',{
diff --git a/content/browser/tab_contents/tab_contents_view_win.cc b/content/browser/tab_contents/tab_contents_view_win.cc
index e2678a5..2ecde72 100644
--- a/content/browser/tab_contents/tab_contents_view_win.cc
+++ b/content/browser/tab_contents/tab_contents_view_win.cc
@@ -9,10 +9,13 @@
#include "content/browser/renderer_host/render_widget_host_view_win.h"
#include "content/browser/tab_contents/interstitial_page_impl.h"
#include "content/browser/tab_contents/tab_contents.h"
+#include "content/browser/tab_contents/web_drag_dest_win.h"
#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_view_win_delegate.h"
using content::RenderWidgetHostView;
using content::WebContents;
+using content::WebContentsViewWinDelegate;
namespace {
@@ -49,28 +52,31 @@ class TempParent : public ui::WindowImpl {
} // namespace namespace
-TabContentsViewWin::TabContentsViewWin(WebContents* web_contents)
- : parent_(NULL),
- tab_contents_(static_cast<TabContents*>(web_contents)),
- view_(NULL) {
+TabContentsViewWin::TabContentsViewWin(WebContents* web_contents,
+ WebContentsViewWinDelegate* delegate)
+ : tab_contents_(static_cast<TabContents*>(web_contents)),
+ view_(NULL),
+ delegate_(delegate) {
}
TabContentsViewWin::~TabContentsViewWin() {
}
-void TabContentsViewWin::SetParent(HWND parent) {
- DCHECK(!parent_);
- parent_ = parent;
-
- ::SetParent(hwnd(), parent_);
-}
-
void TabContentsViewWin::CreateView(const gfx::Size& initial_size) {
initial_size_ = initial_size;
set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
Init(TempParent::Get()->hwnd(), gfx::Rect(initial_size_));
+
+ // Remove the root view drop target so we can register our own.
+ RevokeDragDrop(GetNativeView());
+ drag_dest_ = new WebDragDest(hwnd(), tab_contents_);
+ if (delegate_.get()) {
+ content::WebDragDestDelegate* delegate = delegate_->GetDragDestDelegate();
+ if (delegate)
+ drag_dest_->set_delegate(delegate);
+ }
}
RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget(
@@ -103,7 +109,7 @@ gfx::NativeView TabContentsViewWin::GetContentNativeView() const {
}
gfx::NativeWindow TabContentsViewWin::GetTopLevelNativeWindow() const {
- return parent_;
+ return GetParent(GetNativeView());
}
void TabContentsViewWin::GetContainerBounds(gfx::Rect *out) const {
@@ -151,12 +157,12 @@ void TabContentsViewWin::Focus() {
return;
}
+ if (delegate_.get() && delegate_->Focus())
+ return;
+
RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
- if (rwhv) {
+ if (rwhv)
rwhv->Focus();
- } else {
- SetFocus(hwnd());
- }
}
void TabContentsViewWin::SetInitialFocus() {
@@ -167,12 +173,13 @@ void TabContentsViewWin::SetInitialFocus() {
}
void TabContentsViewWin::StoreFocus() {
- // TODO(jam): why is this on WebContentsView?
- NOTREACHED();
+ if (delegate_.get())
+ delegate_->StoreFocus();
}
void TabContentsViewWin::RestoreFocus() {
- NOTREACHED();
+ if (delegate_.get())
+ delegate_->RestoreFocus();
}
bool TabContentsViewWin::IsDoingDrag() const {
@@ -241,7 +248,14 @@ void TabContentsViewWin::ShowCreatedFullscreenWidget(int route_id) {
void TabContentsViewWin::ShowContextMenu(
const content::ContextMenuParams& params) {
- NOTIMPLEMENTED();
+ // Allow WebContentsDelegates to handle the context menu operation first.
+ if (tab_contents_->GetDelegate() &&
+ tab_contents_->GetDelegate()->HandleContextMenu(params)) {
+ return;
+ }
+
+ if (delegate_.get())
+ delegate_->ShowContextMenu(params);
}
void TabContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds,
@@ -261,7 +275,7 @@ void TabContentsViewWin::StartDragging(const WebDropData& drop_data,
}
void TabContentsViewWin::UpdateDragCursor(WebKit::WebDragOperation operation) {
- NOTIMPLEMENTED();
+ drag_dest_->set_drag_cursor(operation);
}
void TabContentsViewWin::GotFocus() {
@@ -270,8 +284,20 @@ void TabContentsViewWin::GotFocus() {
}
void TabContentsViewWin::TakeFocus(bool reverse) {
- if (tab_contents_->GetDelegate())
- tab_contents_->GetDelegate()->TakeFocus(reverse);
+ if (tab_contents_->GetDelegate() &&
+ !tab_contents_->GetDelegate()->TakeFocus(reverse) &&
+ delegate_.get()) {
+ delegate_->TakeFocus(reverse);
+ }
+}
+
+LRESULT TabContentsViewWin::OnDestroy(
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
+ if (drag_dest_.get()) {
+ RevokeDragDrop(GetNativeView());
+ drag_dest_ = NULL;
+ }
+ return 0;
}
LRESULT TabContentsViewWin::OnWindowPosChanged(
@@ -287,5 +313,8 @@ LRESULT TabContentsViewWin::OnWindowPosChanged(
if (rwhv)
rwhv->SetSize(size);
+ if (delegate_.get())
+ delegate_->SizeChanged(size);
+
return 0;
}
diff --git a/content/browser/tab_contents/tab_contents_view_win.h b/content/browser/tab_contents/tab_contents_view_win.h
index f4f958c..c2ce7d6 100644
--- a/content/browser/tab_contents/tab_contents_view_win.h
+++ b/content/browser/tab_contents/tab_contents_view_win.h
@@ -6,23 +6,31 @@
#define CONTENT_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_WIN_H_
#pragma once
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "content/browser/tab_contents/tab_contents_view_helper.h"
+#include "content/common/content_export.h"
#include "content/public/browser/web_contents_view.h"
#include "ui/base/win/window_impl.h"
class RenderWidgetHostViewWin;
+class WebDragDest;
+
+namespace content {
+class WebContentsViewWinDelegate;
+}
// An implementation of WebContentsView for Windows.
-class TabContentsViewWin : public content::WebContentsView,
- public ui::WindowImpl {
+class CONTENT_EXPORT TabContentsViewWin : public content::WebContentsView,
+ public ui::WindowImpl {
public:
// TODO(jam): make this take a TabContents once it's created from content.
- explicit TabContentsViewWin(content::WebContents* web_contents);
+ TabContentsViewWin(content::WebContents* web_contents,
+ content::WebContentsViewWinDelegate* delegate);
virtual ~TabContentsViewWin();
- void SetParent(HWND parent);
-
BEGIN_MSG_MAP_EX(TabContentsViewWin)
+ MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_WINDOWPOSCHANGED, OnWindowPosChanged)
END_MSG_MAP()
@@ -82,11 +90,11 @@ class TabContentsViewWin : public content::WebContentsView,
TabContents* tab_contents() const { return tab_contents_; }
private:
+ LRESULT OnDestroy(
+ UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
LRESULT OnWindowPosChanged(
UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled);
- HWND parent_;
-
gfx::Size initial_size_;
// The TabContents whose contents we display.
@@ -94,6 +102,12 @@ class TabContentsViewWin : public content::WebContentsView,
RenderWidgetHostViewWin* view_;
+ scoped_ptr<content::WebContentsViewWinDelegate> delegate_;
+
+ // The helper object that handles drag destination related interactions with
+ // Windows.
+ scoped_refptr<WebDragDest> drag_dest_;
+
// Common implementations of some WebContentsView methods.
TabContentsViewHelper tab_contents_view_helper_;
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index e2acdde..af696c1 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -130,6 +130,7 @@
'public/browser/web_contents_view.h',
'public/browser/web_contents_view_gtk_delegate.h',
'public/browser/web_contents_view_mac_delegate.h',
+ 'public/browser/web_contents_view_win_delegate.h',
'public/browser/web_intents_dispatcher.h',
'public/browser/web_ui.h',
'public/browser/web_ui_controller.cc',
@@ -653,6 +654,8 @@
'browser/tab_contents/tab_contents_view_gtk.h',
'browser/tab_contents/tab_contents_view_helper.cc',
'browser/tab_contents/tab_contents_view_helper.h',
+ 'browser/tab_contents/tab_contents_view_win.cc',
+ 'browser/tab_contents/tab_contents_view_win.h',
'browser/tab_contents/web_contents_drag_win.cc',
'browser/tab_contents/web_contents_drag_win.h',
'browser/tab_contents/web_contents_view_android.cc',
@@ -840,6 +843,8 @@
['exclude', '^browser/renderer_host/render_widget_host_view_win.cc'],
['exclude', '^browser/renderer_host/render_widget_host_view_win.h'],
['exclude', '^browser/renderer_host/render_message_filter_win.cc'],
+ ['exclude', '^browser/tab_contents/tab_contents_view_win.cc'],
+ ['exclude', '^browser/tab_contents/tab_contents_view_win.h'],
['exclude', '^browser/tab_contents/web_contents_drag_win.cc'],
['exclude', '^browser/tab_contents/web_contents_drag_win.h'],
['exclude', '^browser/tab_contents/web_drag_dest_win.cc'],
diff --git a/content/content_shell.gypi b/content/content_shell.gypi
index f17ee72..3367064 100644
--- a/content/content_shell.gypi
+++ b/content/content_shell.gypi
@@ -45,8 +45,6 @@
'..',
],
'sources': [
- 'browser/tab_contents/tab_contents_view_win.cc',
- 'browser/tab_contents/tab_contents_view_win.h',
'shell/layout_test_controller_bindings.cc',
'shell/layout_test_controller_bindings.h',
'shell/shell.cc',
diff --git a/content/public/browser/web_contents_view_win_delegate.h b/content/public/browser/web_contents_view_win_delegate.h
new file mode 100644
index 0000000..76bc142
--- /dev/null
+++ b/content/public/browser/web_contents_view_win_delegate.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 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 CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
+#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
+#pragma once
+
+#include "content/common/content_export.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace gfx {
+class Size;
+}
+
+namespace content {
+
+class WebDragDestDelegate;
+struct ContextMenuParams;
+
+// This interface allows a client to extend the functionality of
+// WebContentsViewWin.
+class CONTENT_EXPORT WebContentsViewWinDelegate {
+ public:
+ virtual ~WebContentsViewWinDelegate() {}
+
+ // Returns a delegate to process drags not handled by content.
+ virtual WebDragDestDelegate* GetDragDestDelegate() = 0;
+
+ // These methods allow the embedder to intercept WebContentsViewWin's
+ // implementation of these WebContentsView methods. See the WebContentsView
+ // interface documentation for more information about these methods.
+ virtual void StoreFocus() = 0;
+ virtual void RestoreFocus() = 0;
+ virtual bool Focus() = 0;
+ virtual void TakeFocus(bool reverse) = 0;
+ virtual void ShowContextMenu(const content::ContextMenuParams& params) = 0;
+ virtual void SizeChanged(const gfx::Size& size) = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_VIEW_WIN_DELEGATE_H_
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc
index dfc7344..c0c1365 100644
--- a/content/shell/shell_content_browser_client.cc
+++ b/content/shell/shell_content_browser_client.cc
@@ -46,7 +46,7 @@ WebContentsView* ShellContentBrowserClient::CreateWebContentsView(
devtools_delegate->AddWebContents(web_contents);
#if defined(OS_WIN)
- return new TabContentsViewWin(web_contents);
+ return new TabContentsViewWin(web_contents, NULL);
#elif defined(OS_LINUX)
return new TabContentsViewGtk(web_contents, NULL);
#elif defined(OS_MACOSX)
diff --git a/content/shell/shell_win.cc b/content/shell/shell_win.cc
index 6c74de7..fc95b6e 100644
--- a/content/shell/shell_win.cc
+++ b/content/shell/shell_win.cc
@@ -12,7 +12,7 @@
#include "base/utf_string_conversions.h"
#include "base/win/resource_util.h"
#include "content/browser/tab_contents/tab_contents.h"
-#include "content/browser/tab_contents/tab_contents_view_win.h"
+#include "content/public/browser/web_contents_view.h"
#include "content/shell/resource.h"
#include "googleurl/src/gurl.h"
#include "grit/webkit_resources.h"
@@ -148,9 +148,7 @@ void Shell::PlatformCreateWindow(int width, int height) {
}
void Shell::PlatformSetContents() {
- TabContentsViewWin* view =
- static_cast<TabContentsViewWin*>(tab_contents_->GetView());
- view->SetParent(window_);
+ SetParent(tab_contents_->GetView()->GetNativeView(), window_);
}
void Shell::PlatformSizeTo(int width, int height) {