OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "chrome/browser/views/tabs/browser_tab_strip.h" |
| 6 |
| 7 #include "chrome/browser/tab_contents/tab_contents.h" |
| 8 |
| 9 namespace { |
| 10 |
| 11 //////////////////////////////////////////////////////////////////////////////// |
| 12 // RemovingTabModel |
| 13 // After a tab is removed from the TabStrip2's model, the model can no longer |
| 14 // provide information about the tab needed to update the display, however the |
| 15 // TabStrip2 continues to display the tab until it animates out of existence. |
| 16 // During this period, this model serves as a dummy. It is created and assigned |
| 17 // to the tab when the tab is removed from the model and owned by the Tab2. |
| 18 |
| 19 class RemovingTabModel : public Tab2Model { |
| 20 public: |
| 21 explicit RemovingTabModel(TabContents* source) |
| 22 : title_(source->GetTitle()) { |
| 23 } |
| 24 |
| 25 // Overridden from Tab2Model: |
| 26 virtual string16 GetTitle(Tab2* tab) const { return title_; } |
| 27 virtual bool IsSelected(Tab2* tab) const { return false; } |
| 28 virtual void SelectTab(Tab2* tab) { NOTREACHED(); } |
| 29 virtual void CaptureDragInfo(Tab2* tab, |
| 30 const views::MouseEvent& drag_event) { |
| 31 NOTREACHED(); |
| 32 } |
| 33 virtual bool DragTab(Tab2* tab, const views::MouseEvent& drag_event) { |
| 34 NOTREACHED(); |
| 35 return false; |
| 36 } |
| 37 virtual void DragEnded(Tab2* tab) { |
| 38 NOTREACHED(); |
| 39 } |
| 40 virtual views::AnimatorDelegate* AsAnimatorDelegate() { |
| 41 NOTREACHED(); |
| 42 return NULL; |
| 43 } |
| 44 |
| 45 private: |
| 46 string16 title_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(RemovingTabModel); |
| 49 }; |
| 50 |
| 51 } // namespace |
| 52 |
| 53 //////////////////////////////////////////////////////////////////////////////// |
| 54 // BrowserTabStrip, public: |
| 55 |
| 56 BrowserTabStrip::BrowserTabStrip(TabStripModel* model) |
| 57 : TabStrip2(this), |
| 58 model_(model) { |
| 59 model_->AddObserver(this); |
| 60 } |
| 61 |
| 62 BrowserTabStrip::~BrowserTabStrip() { |
| 63 model_->RemoveObserver(this); |
| 64 } |
| 65 |
| 66 TabContents* BrowserTabStrip::DetachTab(int index) { |
| 67 TabContents* contents = model_->GetTabContentsAt(index); |
| 68 model_->DetachTabContentsAt(index); |
| 69 return contents; |
| 70 } |
| 71 |
| 72 void BrowserTabStrip::AttachTab(TabContents* contents, |
| 73 const gfx::Point& screen_point, |
| 74 const gfx::Rect& tab_screen_bounds) { |
| 75 gfx::Point tabstrip_point(screen_point); |
| 76 |
| 77 gfx::Point screen_origin; |
| 78 View::ConvertPointToScreen(this, &screen_origin); |
| 79 tabstrip_point.Offset(-screen_origin.x(), -screen_origin.y()); |
| 80 |
| 81 int index = GetInsertionIndexForPoint(tabstrip_point); |
| 82 model_->InsertTabContentsAt(index, contents, true, false); |
| 83 |
| 84 gfx::Point origin(tab_screen_bounds.origin()); |
| 85 View::ConvertPointToView(NULL, this, &origin); |
| 86 ResumeDraggingTab(index, gfx::Rect(origin, tab_screen_bounds.size())); |
| 87 // TODO(beng): post task to continue dragging now. |
| 88 } |
| 89 |
| 90 //////////////////////////////////////////////////////////////////////////////// |
| 91 // BrowserTabStrip, TabStripModelObserver overrides: |
| 92 |
| 93 void BrowserTabStrip::TabInsertedAt(TabContents* contents, |
| 94 int index, |
| 95 bool foreground) { |
| 96 AddTabAt(index); |
| 97 } |
| 98 |
| 99 void BrowserTabStrip::TabDetachedAt(TabContents* contents, int index) { |
| 100 RemoveTabAt(index, new RemovingTabModel(contents)); |
| 101 } |
| 102 |
| 103 void BrowserTabStrip::TabSelectedAt(TabContents* old_contents, |
| 104 TabContents* contents, |
| 105 int index, |
| 106 bool user_gesture) { |
| 107 TabStrip2::SelectTabAt(index); |
| 108 } |
| 109 |
| 110 void BrowserTabStrip::TabMoved(TabContents* contents, |
| 111 int from_index, |
| 112 int to_index) { |
| 113 TabStrip2::MoveTabAt(from_index, to_index); |
| 114 } |
| 115 |
| 116 void BrowserTabStrip::TabChangedAt(TabContents* contents, int index) { |
| 117 // TODO |
| 118 } |
| 119 |
| 120 //////////////////////////////////////////////////////////////////////////////// |
| 121 // BrowserTabStrip, TabStrip2Model overrides: |
| 122 |
| 123 string16 BrowserTabStrip::GetTitle(int index) const { |
| 124 return model_->GetTabContentsAt(index)->GetTitle(); |
| 125 } |
| 126 |
| 127 bool BrowserTabStrip::IsSelected(int index) const { |
| 128 return model_->selected_index() == index; |
| 129 } |
| 130 |
| 131 void BrowserTabStrip::SelectTabAt(int index) { |
| 132 model_->SelectTabContentsAt(index, true); |
| 133 } |
| 134 |
| 135 bool BrowserTabStrip::CanDragTabs() const { |
| 136 return model_->delegate()->GetDragActions() != 0; |
| 137 } |
| 138 |
| 139 void BrowserTabStrip::MoveTabAt(int index, int to_index) { |
| 140 model_->MoveTabContentsAt(index, to_index, true); |
| 141 } |
| 142 |
| 143 void BrowserTabStrip::DetachTabAt(int index, const gfx::Rect& window_bounds, |
| 144 const gfx::Rect& tab_bounds) { |
| 145 TabContents* contents = DetachTab(index); |
| 146 model_->delegate()->ContinueDraggingDetachedTab(contents, window_bounds, |
| 147 tab_bounds); |
| 148 } |
OLD | NEW |