summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/frame/browser_root_view.cc
diff options
context:
space:
mode:
authorsky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-13 20:30:35 +0000
committersky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-13 20:30:35 +0000
commit3ddec4cb4f33a3923db591836113fcf803b3f49d (patch)
treeb218286eaa7c0a1dc202d0dc1160250e81fb5ec1 /chrome/browser/views/frame/browser_root_view.cc
parent17e7b20bdf6906f4bdd574a9e0d4526456f3c301 (diff)
downloadchromium_src-3ddec4cb4f33a3923db591836113fcf803b3f49d.zip
chromium_src-3ddec4cb4f33a3923db591836113fcf803b3f49d.tar.gz
chromium_src-3ddec4cb4f33a3923db591836113fcf803b3f49d.tar.bz2
Makes drops above the tabstrip work again. This stopped working
because of changes to the view hiearchy. BUG=8669 TEST=see bug Review URL: http://codereview.chromium.org/42176 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11666 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/frame/browser_root_view.cc')
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
new file mode 100644
index 0000000..c404b2c
--- /dev/null
+++ b/chrome/browser/views/frame/browser_root_view.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2009 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/views/frame/browser_root_view.h"
+
+#include "chrome/browser/views/frame/browser_view.h"
+#include "chrome/browser/views/frame/browser_frame.h"
+#include "chrome/browser/views/tabs/tab_strip.h"
+#include "chrome/common/drag_drop_types.h"
+#include "chrome/common/os_exchange_data.h"
+
+BrowserRootView::BrowserRootView(views::Widget* widget)
+ : views::RootView(widget),
+ tabstrip_(NULL),
+ can_drop_(false),
+ forwarding_to_tab_strip_(false) {
+}
+
+bool BrowserRootView::CanDrop(const OSExchangeData& data) {
+ tabstrip_ =
+ static_cast<BrowserFrame*>(GetWidget())->browser_view()->tabstrip();
+ can_drop_ = (tabstrip_ && tabstrip_->IsVisible() &&
+ !tabstrip_->IsAnimating() && data.HasURL());
+ return can_drop_;
+}
+
+void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
+ if (can_drop_ && ShouldForwardToTabStrip(event)) {
+ forwarding_to_tab_strip_ = true;
+ scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event));
+ tabstrip_->OnDragEntered(*mapped_event.get());
+ }
+}
+
+int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
+ if (can_drop_) {
+ if (ShouldForwardToTabStrip(event)) {
+ scoped_ptr<views::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event));
+ if (!forwarding_to_tab_strip_) {
+ tabstrip_->OnDragEntered(*mapped_event.get());
+ forwarding_to_tab_strip_ = true;
+ }
+ return tabstrip_->OnDragUpdated(*mapped_event.get());
+ } else if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ tabstrip_->OnDragExited();
+ }
+ }
+ return DragDropTypes::DRAG_NONE;
+}
+
+void BrowserRootView::OnDragExited() {
+ if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ tabstrip_->OnDragExited();
+ }
+}
+
+int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) {
+ if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ scoped_ptr<views::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event));
+ return tabstrip_->OnPerformDrop(*mapped_event.get());
+ }
+ return DragDropTypes::DRAG_NONE;
+}
+
+bool BrowserRootView::ShouldForwardToTabStrip(
+ const views::DropTargetEvent& event) {
+ if (!tabstrip_->IsVisible())
+ return false;
+
+ // Allow the drop as long as the mouse is over the tabstrip or vertically
+ // before it.
+ gfx::Point tab_loc_in_host;
+ ConvertPointToView(tabstrip_, this, &tab_loc_in_host);
+ return event.y() < tab_loc_in_host.y() + tabstrip_->height();
+}
+
+views::DropTargetEvent* BrowserRootView::MapEventToTabStrip(
+ const views::DropTargetEvent& event) {
+ gfx::Point tab_strip_loc(event.location());
+ ConvertPointToView(this, tabstrip_, &tab_strip_loc);
+ return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(),
+ tab_strip_loc.y(),
+ event.GetSourceOperations());
+}