summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-13 18:20:04 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-13 18:20:04 +0000
commit9fa3c108d312d6664c51f02f203bc60fd4750156 (patch)
treeee5ccf4a6d05bb3cc79448253ddb24598db143ee /chrome
parent545045f68890e73afc7701a693805aaadf106ea8 (diff)
downloadchromium_src-9fa3c108d312d6664c51f02f203bc60fd4750156.zip
chromium_src-9fa3c108d312d6664c51f02f203bc60fd4750156.tar.gz
chromium_src-9fa3c108d312d6664c51f02f203bc60fd4750156.tar.bz2
Copy contents of FrameView into BrowserView2. Once the old frames retire, we won't need this separate class.
B=1031852 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@818 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/views/frame/browser_view2.cc93
-rw-r--r--chrome/browser/views/frame/browser_view2.h35
2 files changed, 127 insertions, 1 deletions
diff --git a/chrome/browser/views/frame/browser_view2.cc b/chrome/browser/views/frame/browser_view2.cc
index 313652e..0efd982 100644
--- a/chrome/browser/views/frame/browser_view2.cc
+++ b/chrome/browser/views/frame/browser_view2.cc
@@ -41,6 +41,7 @@
#include "chrome/browser/views/status_bubble.h"
#include "chrome/browser/views/toolbar_view.h"
#include "chrome/common/l10n_util.h"
+#include "chrome/common/os_exchange_data.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/resource_bundle.h"
#include "generated_resources.h"
@@ -67,7 +68,9 @@ BrowserView2::BrowserView2(Browser* browser)
active_download_shelf_(NULL),
toolbar_(NULL),
contents_container_(NULL),
- initialized_(false) {
+ initialized_(false),
+ can_drop_(false),
+ forwarding_to_tab_strip_(false) {
InitClass();
show_bookmark_bar_pref_.Init(prefs::kShowBookmarkBar,
browser_->profile()->GetPrefs(), this);
@@ -141,6 +144,10 @@ bool BrowserView2::GetAccelerator(int cmd_id,
return false;
}
+void BrowserView2::AddViewToDropList(ChromeViews::View* view) {
+ dropable_views_.insert(view);
+}
+
bool BrowserView2::SupportsWindowFeature(WindowFeature feature) const {
return !!(FeaturesForBrowserType(browser_->GetType()) & feature);
}
@@ -593,11 +600,95 @@ void BrowserView2::ViewHierarchyChanged(bool is_add,
Init();
initialized_ = true;
}
+ if (!is_add)
+ dropable_views_.erase(child);
+}
+
+bool BrowserView2::CanDrop(const OSExchangeData& data) {
+ can_drop_ = (tabstrip_->IsVisible() && !tabstrip_->IsAnimating() &&
+ data.HasURL());
+ return can_drop_;
+}
+
+void BrowserView2::OnDragEntered(const ChromeViews::DropTargetEvent& event) {
+ if (can_drop_ && ShouldForwardToTabStrip(event)) {
+ forwarding_to_tab_strip_ = true;
+ scoped_ptr<ChromeViews::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event));
+ tabstrip_->OnDragEntered(*mapped_event.get());
+ }
+}
+
+int BrowserView2::OnDragUpdated(const ChromeViews::DropTargetEvent& event) {
+ if (can_drop_) {
+ if (ShouldForwardToTabStrip(event)) {
+ scoped_ptr<ChromeViews::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 BrowserView2::OnDragExited() {
+ if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ tabstrip_->OnDragExited();
+ }
}
+int BrowserView2::OnPerformDrop(const ChromeViews::DropTargetEvent& event) {
+ if (forwarding_to_tab_strip_) {
+ forwarding_to_tab_strip_ = false;
+ scoped_ptr<ChromeViews::DropTargetEvent> mapped_event(
+ MapEventToTabStrip(event));
+ return tabstrip_->OnPerformDrop(*mapped_event.get());
+ }
+ return DragDropTypes::DRAG_NONE;
+}
+
+
///////////////////////////////////////////////////////////////////////////////
// BrowserView2, private:
+bool BrowserView2::ShouldForwardToTabStrip(
+ const ChromeViews::DropTargetEvent& event) {
+ if (!tabstrip_->IsVisible())
+ return false;
+
+ const int tab_y = tabstrip_->GetY();
+ const int tab_height = tabstrip_->GetHeight();
+ if (event.GetY() >= tab_y + tab_height)
+ return false;
+
+ if (event.GetY() >= tab_y)
+ return true;
+
+ // Mouse isn't over the tab strip. Only forward if the mouse isn't over
+ // another view on the tab strip or is over a view we were told the user can
+ // drop on.
+ ChromeViews::View* view_over_mouse =
+ GetViewForPoint(CPoint(event.GetX(), event.GetY()));
+ return (view_over_mouse == this || view_over_mouse == tabstrip_ ||
+ dropable_views_.find(view_over_mouse) != dropable_views_.end());
+}
+
+ChromeViews::DropTargetEvent* BrowserView2::MapEventToTabStrip(
+ const ChromeViews::DropTargetEvent& event) {
+ gfx::Point tab_strip_loc(event.location());
+ ConvertPointToView(this, tabstrip_, &tab_strip_loc);
+ return new ChromeViews::DropTargetEvent(event.GetData(), tab_strip_loc.x(),
+ tab_strip_loc.y(),
+ event.GetSourceOperations());
+}
+
int BrowserView2::LayoutTabStrip() {
if (IsTabStripVisible()) {
gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_);
diff --git a/chrome/browser/views/frame/browser_view2.h b/chrome/browser/views/frame/browser_view2.h
index 54f154c..ef3b7c8 100644
--- a/chrome/browser/views/frame/browser_view2.h
+++ b/chrome/browser/views/frame/browser_view2.h
@@ -92,6 +92,11 @@ class BrowserView2 : public BrowserWindow,
// otherwise.
bool GetAccelerator(int cmd_id, ChromeViews::Accelerator* accelerator);
+ // Adds view to the set of views that drops are allowed to occur on. You only
+ // need invoke this for views whose y-coordinate extends above the tab strip
+ // and you want to allow drops on.
+ void AddViewToDropList(ChromeViews::View* view);
+
// Possible elements of the Browser window.
enum WindowFeature {
FEATURE_TITLEBAR = 1,
@@ -180,6 +185,7 @@ class BrowserView2 : public BrowserWindow,
virtual bool CanClose() const;
virtual int NonClientHitTest(const gfx::Point& point);
+ protected:
// Overridden from ChromeViews::View:
virtual void Paint(ChromeCanvas* canvas);
virtual void Layout();
@@ -187,8 +193,26 @@ class BrowserView2 : public BrowserWindow,
virtual void ViewHierarchyChanged(bool is_add,
ChromeViews::View* parent,
ChromeViews::View* child);
+ // As long as ShouldForwardToTabStrip returns true, drag and drop methods
+ // are forwarded to the tab strip.
+ virtual bool CanDrop(const OSExchangeData& data);
+ virtual void OnDragEntered(const ChromeViews::DropTargetEvent& event);
+ virtual int OnDragUpdated(const ChromeViews::DropTargetEvent& event);
+ virtual void OnDragExited();
+ virtual int OnPerformDrop(const ChromeViews::DropTargetEvent& event);
private:
+ // Returns true if the event should be forwarded to the TabStrip. This
+ // returns true if y coordinate is less than the bottom of the tab strip, and
+ // is not over another child view.
+ virtual bool ShouldForwardToTabStrip(
+ const ChromeViews::DropTargetEvent& event);
+
+ // Creates and returns a new DropTargetEvent in the coordinates of the
+ // TabStrip.
+ ChromeViews::DropTargetEvent* MapEventToTabStrip(
+ const ChromeViews::DropTargetEvent& event);
+
// Layout the TabStrip, returns the coordinate of the bottom of the TabStrip,
// for laying out subsequent controls.
int LayoutTabStrip();
@@ -284,6 +308,17 @@ class BrowserView2 : public BrowserWindow,
// The default favicon image.
static SkBitmap default_favicon_;
+ // Initially set in CanDrop by invoking the same method on the TabStrip.
+ bool can_drop_;
+
+ // If true, drag and drop events are being forwarded to the tab strip.
+ // This is used to determine when to send OnDragExited and OnDragExited
+ // to the tab strip.
+ bool forwarding_to_tab_strip_;
+
+ // Set of additional views drops are allowed on. We do NOT own these.
+ std::set<ChromeViews::View*> dropable_views_;
+
DISALLOW_EVIL_CONSTRUCTORS(BrowserView2);
};