Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: chrome/browser/views/frame/browser_root_view.cc

Issue 42318: Merge r11666.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/branches/169/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/frame/browser_root_view.h"
6
7 #include "chrome/browser/views/frame/browser_view.h"
8 #include "chrome/browser/views/frame/browser_frame.h"
9 #include "chrome/browser/views/tabs/tab_strip.h"
10 #include "chrome/common/drag_drop_types.h"
11 #include "chrome/common/os_exchange_data.h"
12
13 BrowserRootView::BrowserRootView(views::Widget* widget)
14 : views::RootView(widget),
15 tabstrip_(NULL),
16 can_drop_(false),
17 forwarding_to_tab_strip_(false) {
18 }
19
20 bool BrowserRootView::CanDrop(const OSExchangeData& data) {
21 tabstrip_ =
22 static_cast<BrowserFrame*>(GetWidget())->browser_view()->tabstrip();
23 can_drop_ = (tabstrip_ && tabstrip_->IsVisible() &&
24 !tabstrip_->IsAnimating() && data.HasURL());
25 return can_drop_;
26 }
27
28 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) {
29 if (can_drop_ && ShouldForwardToTabStrip(event)) {
30 forwarding_to_tab_strip_ = true;
31 scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event));
32 tabstrip_->OnDragEntered(*mapped_event.get());
33 }
34 }
35
36 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) {
37 if (can_drop_) {
38 if (ShouldForwardToTabStrip(event)) {
39 scoped_ptr<views::DropTargetEvent> mapped_event(
40 MapEventToTabStrip(event));
41 if (!forwarding_to_tab_strip_) {
42 tabstrip_->OnDragEntered(*mapped_event.get());
43 forwarding_to_tab_strip_ = true;
44 }
45 return tabstrip_->OnDragUpdated(*mapped_event.get());
46 } else if (forwarding_to_tab_strip_) {
47 forwarding_to_tab_strip_ = false;
48 tabstrip_->OnDragExited();
49 }
50 }
51 return DragDropTypes::DRAG_NONE;
52 }
53
54 void BrowserRootView::OnDragExited() {
55 if (forwarding_to_tab_strip_) {
56 forwarding_to_tab_strip_ = false;
57 tabstrip_->OnDragExited();
58 }
59 }
60
61 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) {
62 if (forwarding_to_tab_strip_) {
63 forwarding_to_tab_strip_ = false;
64 scoped_ptr<views::DropTargetEvent> mapped_event(
65 MapEventToTabStrip(event));
66 return tabstrip_->OnPerformDrop(*mapped_event.get());
67 }
68 return DragDropTypes::DRAG_NONE;
69 }
70
71 bool BrowserRootView::ShouldForwardToTabStrip(
72 const views::DropTargetEvent& event) {
73 if (!tabstrip_->IsVisible())
74 return false;
75
76 // Allow the drop as long as the mouse is over the tabstrip or vertically
77 // before it.
78 gfx::Point tab_loc_in_host;
79 ConvertPointToView(tabstrip_, this, &tab_loc_in_host);
80 return event.y() < tab_loc_in_host.y() + tabstrip_->height();
81 }
82
83 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip(
84 const views::DropTargetEvent& event) {
85 gfx::Point tab_strip_loc(event.location());
86 ConvertPointToView(this, tabstrip_, &tab_strip_loc);
87 return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(),
88 tab_strip_loc.y(),
89 event.GetSourceOperations());
90 }
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/browser_root_view.h ('k') | chrome/browser/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698