diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 20:30:35 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 20:30:35 +0000 |
commit | 3ddec4cb4f33a3923db591836113fcf803b3f49d (patch) | |
tree | b218286eaa7c0a1dc202d0dc1160250e81fb5ec1 /chrome | |
parent | 17e7b20bdf6906f4bdd574a9e0d4526456f3c301 (diff) | |
download | chromium_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')
-rw-r--r-- | chrome/browser/views/browser_views.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_frame.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_frame.h | 3 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_root_view.cc | 90 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_root_view.h | 51 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 96 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 34 | ||||
-rw-r--r-- | chrome/browser/views/frame/glass_browser_frame_view.h | 2 | ||||
-rw-r--r-- | chrome/views/non_client_view.h | 2 |
9 files changed, 164 insertions, 128 deletions
diff --git a/chrome/browser/views/browser_views.vcproj b/chrome/browser/views/browser_views.vcproj index 41b7bb1..7e14a55 100644 --- a/chrome/browser/views/browser_views.vcproj +++ b/chrome/browser/views/browser_views.vcproj @@ -133,6 +133,14 @@ > </File> <File + RelativePath=".\frame\browser_root_view.cc" + > + </File> + <File + RelativePath=".\frame\browser_root_view.h" + > + </File> + <File RelativePath=".\frame\browser_view.cc" > </File> diff --git a/chrome/browser/views/frame/browser_frame.cc b/chrome/browser/views/frame/browser_frame.cc index 99542c3..31bf41d 100644 --- a/chrome/browser/views/frame/browser_frame.cc +++ b/chrome/browser/views/frame/browser_frame.cc @@ -8,6 +8,7 @@ #include <shellapi.h> #include "chrome/browser/browser_list.h" +#include "chrome/browser/views/frame/browser_root_view.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/frame/glass_browser_frame_view.h" #include "chrome/browser/views/frame/opaque_browser_frame_view.h" @@ -202,6 +203,11 @@ void BrowserFrame::UpdateFrameAfterFrameChange() { UpdateDWMFrame(); } + +views::RootView* BrowserFrame::CreateRootView() { + return new BrowserRootView(this); +} + /////////////////////////////////////////////////////////////////////////////// // BrowserFrame, private: diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h index 95ce96e..7414719 100644 --- a/chrome/browser/views/frame/browser_frame.h +++ b/chrome/browser/views/frame/browser_frame.h @@ -51,6 +51,8 @@ class BrowserFrame : public views::Window { // Tells the frame to update the throbber. void UpdateThrobber(bool running); + BrowserView* browser_view() const { return browser_view_; } + protected: // Overridden from views::WidgetWin: virtual bool AcceleratorPressed(views::Accelerator* accelerator); @@ -72,6 +74,7 @@ class BrowserFrame : public views::Window { virtual bool IsAppWindow() const { return true; } virtual views::NonClientFrameView* CreateFrameViewForWindow(); virtual void UpdateFrameAfterFrameChange(); + virtual views::RootView* CreateRootView(); private: // Updates the DWM with the frame bounds. 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()); +} diff --git a/chrome/browser/views/frame/browser_root_view.h b/chrome/browser/views/frame/browser_root_view.h new file mode 100644 index 0000000..df11de7 --- /dev/null +++ b/chrome/browser/views/frame/browser_root_view.h @@ -0,0 +1,51 @@ +// 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. + +#ifndef CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H +#define CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H + +#include "chrome/views/root_view.h" + +class OSExchangeData; +class TabStrip; + +// RootView implementation used by BrowserFrame. This forwards drop events to +// the TabStrip. Visually the tabstrip extends to the top of the frame, but in +// actually it doesn't. The tabstrip is only as high as a tab. To enable +// dropping above the tabstrip BrowserRootView forwards drop events to the +// TabStrip. +class BrowserRootView : public views::RootView { + public: + explicit BrowserRootView(views::Widget* widget); + + virtual bool CanDrop(const OSExchangeData& data); + virtual void OnDragEntered(const views::DropTargetEvent& event); + virtual int OnDragUpdated(const views::DropTargetEvent& event); + virtual void OnDragExited(); + virtual int OnPerformDrop(const views::DropTargetEvent& event); + + private: + // Returns true if the event should be forwarded to the tabstrip. + bool ShouldForwardToTabStrip(const views::DropTargetEvent& event); + + // Converts the event from the hosts coordinate system to the tabstrips + // coordinate system. + views::DropTargetEvent* MapEventToTabStrip( + const views::DropTargetEvent& event); + + // The TabStrip. + TabStrip* tabstrip_; + + // Is a drop allowed? This is set by CanDrop. + bool can_drop_; + + // If true, drag and drop events are being forwarded to the tab strip. + // This is used to determine when to send OnDragEntered and OnDragExited + // to the tab strip. + bool forwarding_to_tab_strip_; + + DISALLOW_COPY_AND_ASSIGN(BrowserRootView); +}; + +#endif // CHROME_BROWSER_VIEWS_FRAME_BROWSER_ROOT_VIEW_H diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 69b14f2..f8d81d9 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -210,14 +210,13 @@ BrowserView::BrowserView(Browser* browser) initialized_(false), fullscreen_(false), ignore_layout_(false), - can_drop_(false), hung_window_detector_(&hung_plugin_action_), - ticker_(0), + ticker_(0) #ifdef CHROME_PERSONALIZATION - personalization_enabled_(false), - personalization_(NULL), + , personalization_enabled_(false), + personalization_(NULL) #endif - forwarding_to_tab_strip_(false) { + { InitClass(); browser_->tabstrip_model()->AddObserver(this); } @@ -377,10 +376,6 @@ bool BrowserView::GetAccelerator(int cmd_id, views::Accelerator* accelerator) { return false; } -void BrowserView::AddViewToDropList(views::View* view) { - dropable_views_.insert(view); -} - bool BrowserView::ActivateAppModalDialog() const { // If another browser is app modal, flash and activate the modal browser. if (AppModalDialogQueue::HasActiveDialog()) { @@ -1275,61 +1270,8 @@ void BrowserView::ViewHierarchyChanged(bool is_add, Init(); initialized_ = true; } - if (!is_add) - dropable_views_.erase(child); -} - -bool BrowserView::CanDrop(const OSExchangeData& data) { - can_drop_ = (tabstrip_->IsVisible() && !tabstrip_->IsAnimating() && - data.HasURL()); - return can_drop_; -} - -void BrowserView::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 BrowserView::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 BrowserView::OnDragExited() { - if (forwarding_to_tab_strip_) { - forwarding_to_tab_strip_ = false; - tabstrip_->OnDragExited(); - } -} - -int BrowserView::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; -} - - /////////////////////////////////////////////////////////////////////////////// // BrowserView, private: @@ -1350,36 +1292,6 @@ void BrowserView::InitSystemMenu() { } } -bool BrowserView::ShouldForwardToTabStrip( - const views::DropTargetEvent& event) { - if (!tabstrip_->IsVisible()) - return false; - - const int tab_y = tabstrip_->y(); - const int tab_height = tabstrip_->height(); - if (event.y() >= tab_y + tab_height) - return false; - - if (event.y() >= 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. - views::View* view_over_mouse = GetViewForPoint(event.location()); - return (view_over_mouse == this || view_over_mouse == tabstrip_ || - dropable_views_.find(view_over_mouse) != dropable_views_.end()); -} - -views::DropTargetEvent* BrowserView::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()); -} - int BrowserView::LayoutTabStrip() { gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); gfx::Point tabstrip_origin = tabstrip_bounds.origin(); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index 44d9e0c..0229e73 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -129,11 +129,6 @@ class BrowserView : public BrowserWindow, // handled. bool SystemCommandReceived(UINT notification_code, const gfx::Point& point); - // 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(views::View* view); - // Shows the next app-modal dialog box, if there is one to be shown, or moves // an existing showing one to the front. Returns true if one was shown or // activated, false if none was shown. @@ -270,14 +265,6 @@ class BrowserView : public BrowserWindow, virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::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 views::DropTargetEvent& event); - virtual int OnDragUpdated(const views::DropTargetEvent& event); - virtual void OnDragExited(); - virtual int OnPerformDrop(const views::DropTargetEvent& event); - private: // Information saved before going into fullscreen mode, used to restore the // window afterwards. @@ -291,16 +278,6 @@ class BrowserView : public BrowserWindow, // Creates the system menu. void InitSystemMenu(); - // 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 views::DropTargetEvent& event); - - // Creates and returns a new DropTargetEvent in the coordinates of the - // TabStrip. - views::DropTargetEvent* MapEventToTabStrip( - const views::DropTargetEvent& event); - // Layout the TabStrip, returns the coordinate of the bottom of the TabStrip, // for laying out subsequent controls. int LayoutTabStrip(); @@ -430,17 +407,6 @@ class BrowserView : 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<views::View*> dropable_views_; - // The OTR avatar image. static SkBitmap otr_avatar_; diff --git a/chrome/browser/views/frame/glass_browser_frame_view.h b/chrome/browser/views/frame/glass_browser_frame_view.h index bf25210..90bbc9c 100644 --- a/chrome/browser/views/frame/glass_browser_frame_view.h +++ b/chrome/browser/views/frame/glass_browser_frame_view.h @@ -6,8 +6,8 @@ #define CHROME_BROWSER_VIEWS_FRAME_GLASS_BROWSER_FRAME_VIEW_H_ #include "chrome/browser/views/frame/browser_frame.h" -#include "chrome/views/non_client_view.h" #include "chrome/views/button.h" +#include "chrome/views/non_client_view.h" class BrowserView; class GlassBrowserWindowResources; diff --git a/chrome/views/non_client_view.h b/chrome/views/non_client_view.h index abb2e6ed..9561052 100644 --- a/chrome/views/non_client_view.h +++ b/chrome/views/non_client_view.h @@ -99,7 +99,7 @@ class NonClientFrameView : public View { // +- views::Window ------------------------------------+ // | +- views::RootView ------------------------------+ | // | | +- views::NonClientView ---------------------+ | | -// | | | +- views::NonClientFrameView subclass ---+ | | | +// | | | +- views::NonClientView subclass ---+ | | | // | | | | | | | | // | | | | << all painting and event receiving >> | | | | // | | | | << of the non-client areas of a >> | | | | |