OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/views/frame/browser_root_view.h" | 5 #include "chrome/browser/views/frame/browser_root_view.h" |
6 | 6 |
7 #include "app/drag_drop_types.h" | 7 #include "app/drag_drop_types.h" |
8 #include "app/os_exchange_data.h" | 8 #include "app/os_exchange_data.h" |
9 #include "chrome/browser/views/frame/browser_view.h" | 9 #include "chrome/browser/views/frame/browser_view.h" |
10 #include "chrome/browser/views/frame/browser_frame.h" | 10 #include "chrome/browser/views/frame/browser_frame.h" |
11 #include "chrome/browser/views/tabs/tab_strip.h" | 11 #include "chrome/browser/views/tabs/tab_strip_wrapper.h" |
12 | 12 |
13 BrowserRootView::BrowserRootView(views::Widget* widget) | 13 BrowserRootView::BrowserRootView(views::Widget* widget) |
14 : views::RootView(widget), | 14 : views::RootView(widget), |
15 tabstrip_(NULL), | 15 tabstrip_(NULL), |
16 can_drop_(false), | 16 can_drop_(false), |
17 forwarding_to_tab_strip_(false) { | 17 forwarding_to_tab_strip_(false) { |
18 } | 18 } |
19 | 19 |
20 bool BrowserRootView::CanDrop(const OSExchangeData& data) { | 20 bool BrowserRootView::CanDrop(const OSExchangeData& data) { |
21 can_drop_ = (tabstrip_ && tabstrip_->IsVisible() && | 21 can_drop_ = (tabstrip_ && tabstrip_->GetView()->IsVisible() && |
22 !tabstrip_->IsAnimating() && data.HasURL()); | 22 !tabstrip_->IsAnimating() && data.HasURL()); |
23 return can_drop_; | 23 return can_drop_; |
24 } | 24 } |
25 | 25 |
26 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { | 26 void BrowserRootView::OnDragEntered(const views::DropTargetEvent& event) { |
27 if (can_drop_ && ShouldForwardToTabStrip(event)) { | 27 if (can_drop_ && ShouldForwardToTabStrip(event)) { |
28 forwarding_to_tab_strip_ = true; | 28 forwarding_to_tab_strip_ = true; |
29 scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event)); | 29 scoped_ptr<views::DropTargetEvent> mapped_event(MapEventToTabStrip(event)); |
30 tabstrip_->OnDragEntered(*mapped_event.get()); | 30 tabstrip_->GetView()->OnDragEntered(*mapped_event.get()); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { | 34 int BrowserRootView::OnDragUpdated(const views::DropTargetEvent& event) { |
35 if (can_drop_) { | 35 if (can_drop_) { |
36 if (ShouldForwardToTabStrip(event)) { | 36 if (ShouldForwardToTabStrip(event)) { |
37 scoped_ptr<views::DropTargetEvent> mapped_event( | 37 scoped_ptr<views::DropTargetEvent> mapped_event( |
38 MapEventToTabStrip(event)); | 38 MapEventToTabStrip(event)); |
39 if (!forwarding_to_tab_strip_) { | 39 if (!forwarding_to_tab_strip_) { |
40 tabstrip_->OnDragEntered(*mapped_event.get()); | 40 tabstrip_->GetView()->OnDragEntered(*mapped_event.get()); |
41 forwarding_to_tab_strip_ = true; | 41 forwarding_to_tab_strip_ = true; |
42 } | 42 } |
43 return tabstrip_->OnDragUpdated(*mapped_event.get()); | 43 return tabstrip_->GetView()->OnDragUpdated(*mapped_event.get()); |
44 } else if (forwarding_to_tab_strip_) { | 44 } else if (forwarding_to_tab_strip_) { |
45 forwarding_to_tab_strip_ = false; | 45 forwarding_to_tab_strip_ = false; |
46 tabstrip_->OnDragExited(); | 46 tabstrip_->GetView()->OnDragExited(); |
47 } | 47 } |
48 } | 48 } |
49 return DragDropTypes::DRAG_NONE; | 49 return DragDropTypes::DRAG_NONE; |
50 } | 50 } |
51 | 51 |
52 void BrowserRootView::OnDragExited() { | 52 void BrowserRootView::OnDragExited() { |
53 if (forwarding_to_tab_strip_) { | 53 if (forwarding_to_tab_strip_) { |
54 forwarding_to_tab_strip_ = false; | 54 forwarding_to_tab_strip_ = false; |
55 tabstrip_->OnDragExited(); | 55 tabstrip_->GetView()->OnDragExited(); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { | 59 int BrowserRootView::OnPerformDrop(const views::DropTargetEvent& event) { |
60 if (forwarding_to_tab_strip_) { | 60 if (forwarding_to_tab_strip_) { |
61 forwarding_to_tab_strip_ = false; | 61 forwarding_to_tab_strip_ = false; |
62 scoped_ptr<views::DropTargetEvent> mapped_event( | 62 scoped_ptr<views::DropTargetEvent> mapped_event( |
63 MapEventToTabStrip(event)); | 63 MapEventToTabStrip(event)); |
64 return tabstrip_->OnPerformDrop(*mapped_event.get()); | 64 return tabstrip_->GetView()->OnPerformDrop(*mapped_event.get()); |
65 } | 65 } |
66 return DragDropTypes::DRAG_NONE; | 66 return DragDropTypes::DRAG_NONE; |
67 } | 67 } |
68 | 68 |
69 bool BrowserRootView::ShouldForwardToTabStrip( | 69 bool BrowserRootView::ShouldForwardToTabStrip( |
70 const views::DropTargetEvent& event) { | 70 const views::DropTargetEvent& event) { |
71 if (!tabstrip_->IsVisible()) | 71 if (!tabstrip_->GetView()->IsVisible()) |
72 return false; | 72 return false; |
73 | 73 |
74 // Allow the drop as long as the mouse is over the tabstrip or vertically | 74 // Allow the drop as long as the mouse is over the tabstrip or vertically |
75 // before it. | 75 // before it. |
76 gfx::Point tab_loc_in_host; | 76 gfx::Point tab_loc_in_host; |
77 ConvertPointToView(tabstrip_, this, &tab_loc_in_host); | 77 ConvertPointToView(tabstrip_->GetView(), this, &tab_loc_in_host); |
78 return event.y() < tab_loc_in_host.y() + tabstrip_->height(); | 78 return event.y() < tab_loc_in_host.y() + tabstrip_->GetView()->height(); |
79 } | 79 } |
80 | 80 |
81 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( | 81 views::DropTargetEvent* BrowserRootView::MapEventToTabStrip( |
82 const views::DropTargetEvent& event) { | 82 const views::DropTargetEvent& event) { |
83 gfx::Point tab_strip_loc(event.location()); | 83 gfx::Point tab_strip_loc(event.location()); |
84 ConvertPointToView(this, tabstrip_, &tab_strip_loc); | 84 ConvertPointToView(this, tabstrip_->GetView(), &tab_strip_loc); |
85 return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(), | 85 return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(), |
86 tab_strip_loc.y(), | 86 tab_strip_loc.y(), |
87 event.GetSourceOperations()); | 87 event.GetSourceOperations()); |
88 } | 88 } |
OLD | NEW |