OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/wm_overview_controller.h" | 5 #include "chrome/browser/chromeos/wm_overview_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/linked_ptr.h" | 10 #include "base/linked_ptr.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/wm_ipc.h" | 12 #include "chrome/browser/chromeos/wm_ipc.h" |
13 #include "chrome/browser/chromeos/wm_overview_fav_icon.h" | 13 #include "chrome/browser/chromeos/wm_overview_fav_icon.h" |
14 #include "chrome/browser/chromeos/wm_overview_snapshot.h" | 14 #include "chrome/browser/chromeos/wm_overview_snapshot.h" |
15 #include "chrome/browser/chromeos/wm_overview_title.h" | 15 #include "chrome/browser/chromeos/wm_overview_title.h" |
16 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
17 #include "chrome/browser/renderer_host/render_widget_host.h" | 17 #include "chrome/browser/renderer_host/render_widget_host.h" |
18 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 18 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
20 #include "chrome/browser/tab_contents/tab_contents_view.h" | 20 #include "chrome/browser/tab_contents/tab_contents_view.h" |
21 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 21 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 22 #include "chrome/browser/tab_contents_wrapper.h" |
22 #include "chrome/browser/tabs/tab_strip_model.h" | 23 #include "chrome/browser/tabs/tab_strip_model.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/views/frame/browser_view.h" | 25 #include "chrome/browser/views/frame/browser_view.h" |
25 #include "chrome/common/notification_service.h" | 26 #include "chrome/common/notification_service.h" |
26 #include "views/widget/root_view.h" | 27 #include "views/widget/root_view.h" |
27 #include "views/widget/widget_gtk.h" | 28 #include "views/widget/widget_gtk.h" |
28 #include "views/window/window.h" | 29 #include "views/window/window.h" |
29 | 30 |
30 using std::vector; | 31 using std::vector; |
31 | 32 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 65 |
65 // The number of additional padding pixels to remove from the title width. | 66 // The number of additional padding pixels to remove from the title width. |
66 static const int kFavIconPadding = 5; | 67 static const int kFavIconPadding = 5; |
67 | 68 |
68 class BrowserListener : public TabStripModelObserver { | 69 class BrowserListener : public TabStripModelObserver { |
69 public: | 70 public: |
70 BrowserListener(Browser* browser, WmOverviewController* parent); | 71 BrowserListener(Browser* browser, WmOverviewController* parent); |
71 ~BrowserListener(); | 72 ~BrowserListener(); |
72 | 73 |
73 // Begin TabStripModelObserver methods | 74 // Begin TabStripModelObserver methods |
74 virtual void TabInsertedAt(TabContents* contents, | 75 virtual void TabInsertedAt(TabContentsWrapper* contents, |
75 int index, | 76 int index, |
76 bool foreground); | 77 bool foreground); |
77 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 78 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
78 TabContents* contents, | 79 TabContentsWrapper* contents, |
79 int index) {} | 80 int index) {} |
80 virtual void TabDetachedAt(TabContents* contents, int index); | 81 virtual void TabDetachedAt(TabContentsWrapper* contents, int index); |
81 virtual void TabMoved(TabContents* contents, | 82 virtual void TabMoved(TabContentsWrapper* contents, |
82 int from_index, | 83 int from_index, |
83 int to_index); | 84 int to_index); |
84 virtual void TabChangedAt(TabContents* contents, int index, | 85 virtual void TabChangedAt(TabContentsWrapper* contents, int index, |
85 TabStripModelObserver::TabChangeType change_type); | 86 TabStripModelObserver::TabChangeType change_type); |
86 virtual void TabStripEmpty(); | 87 virtual void TabStripEmpty(); |
87 virtual void TabDeselectedAt(TabContents* contents, int index) {} | 88 virtual void TabDeselectedAt(TabContentsWrapper* contents, int index) {} |
88 virtual void TabSelectedAt(TabContents* old_contents, | 89 virtual void TabSelectedAt(TabContentsWrapper* old_contents, |
89 TabContents* new_contents, | 90 TabContentsWrapper* new_contents, |
90 int index, | 91 int index, |
91 bool user_gesture); | 92 bool user_gesture); |
92 // End TabStripModelObserver methods | 93 // End TabStripModelObserver methods |
93 | 94 |
94 // Returns the number of tabs in this child. | 95 // Returns the number of tabs in this child. |
95 int count() const { return browser_->tabstrip_model()->count(); } | 96 int count() const { return browser_->tabstrip_model()->count(); } |
96 | 97 |
97 // Returns the browser that this child gets its data from. | 98 // Returns the browser that this child gets its data from. |
98 Browser* browser() const { return browser_; } | 99 Browser* browser() const { return browser_; } |
99 | 100 |
(...skipping 20 matching lines...) Expand all Loading... |
120 void RestoreOriginalSelectedTab(); | 121 void RestoreOriginalSelectedTab(); |
121 | 122 |
122 // Selects the tab at the given index. | 123 // Selects the tab at the given index. |
123 void SelectTab(int index, uint32 timestamp); | 124 void SelectTab(int index, uint32 timestamp); |
124 | 125 |
125 // Shows any snapshots that are not visible. | 126 // Shows any snapshots that are not visible. |
126 void ShowSnapshots(); | 127 void ShowSnapshots(); |
127 | 128 |
128 // Returns the tab contents from the tab model for this child at index. | 129 // Returns the tab contents from the tab model for this child at index. |
129 TabContents* GetTabContentsAt(int index) const { | 130 TabContents* GetTabContentsAt(int index) const { |
130 return browser_->tabstrip_model()->GetTabContentsAt(index); | 131 return browser_->tabstrip_model()->GetTabContentsAt(index)->tab_contents(); |
131 } | 132 } |
132 private: | 133 private: |
133 // Calculate the size of a cell based on the browser window's size. | 134 // Calculate the size of a cell based on the browser window's size. |
134 gfx::Size CalculateCellSize(); | 135 gfx::Size CalculateCellSize(); |
135 | 136 |
136 // Configures a cell from the tab contents. | 137 // Configures a cell from the tab contents. |
137 void ConfigureCell(WmOverviewSnapshot* cell, TabContents* contents); | 138 void ConfigureCell(WmOverviewSnapshot* cell, TabContents* contents); |
138 | 139 |
139 // Configures a cell from the model. | 140 // Configures a cell from the model. |
140 void ConfigureCell(WmOverviewSnapshot* cell, int index) { | 141 void ConfigureCell(WmOverviewSnapshot* cell, int index) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // This browser didn't already exist, and so we haven't been | 197 // This browser didn't already exist, and so we haven't been |
197 // watching it for tab insertions, so we need to create the | 198 // watching it for tab insertions, so we need to create the |
198 // snapshots associated with it. | 199 // snapshots associated with it. |
199 RecreateSnapshots(); | 200 RecreateSnapshots(); |
200 } | 201 } |
201 | 202 |
202 BrowserListener::~BrowserListener() { | 203 BrowserListener::~BrowserListener() { |
203 browser_->tabstrip_model()->RemoveObserver(this); | 204 browser_->tabstrip_model()->RemoveObserver(this); |
204 } | 205 } |
205 | 206 |
206 void BrowserListener::TabInsertedAt(TabContents* contents, | 207 void BrowserListener::TabInsertedAt(TabContentsWrapper* contents, |
207 int index, | 208 int index, |
208 bool foreground) { | 209 bool foreground) { |
209 InsertSnapshot(index); | 210 InsertSnapshot(index); |
210 RenumberSnapshots(index); | 211 RenumberSnapshots(index); |
211 UpdateSelectedIndex(browser_->selected_index()); | 212 UpdateSelectedIndex(browser_->selected_index()); |
212 } | 213 } |
213 | 214 |
214 void BrowserListener::TabDetachedAt(TabContents* contents, int index) { | 215 void BrowserListener::TabDetachedAt(TabContentsWrapper* contents, int index) { |
215 ClearSnapshot(index); | 216 ClearSnapshot(index); |
216 UpdateSelectedIndex(browser_->selected_index()); | 217 UpdateSelectedIndex(browser_->selected_index()); |
217 RenumberSnapshots(index); | 218 RenumberSnapshots(index); |
218 } | 219 } |
219 | 220 |
220 void BrowserListener::TabMoved(TabContents* contents, | 221 void BrowserListener::TabMoved(TabContentsWrapper* contents, |
221 int from_index, | 222 int from_index, |
222 int to_index) { | 223 int to_index) { |
223 // Need to reorder tab in the snapshots list, and reset the window | 224 // Need to reorder tab in the snapshots list, and reset the window |
224 // type atom on the affected snapshots (the one moved, and all the | 225 // type atom on the affected snapshots (the one moved, and all the |
225 // ones after it), so that their indices are correct. | 226 // ones after it), so that their indices are correct. |
226 SnapshotNode node = snapshots_[from_index]; | 227 SnapshotNode node = snapshots_[from_index]; |
227 snapshots_.erase(snapshots_.begin() + from_index); | 228 snapshots_.erase(snapshots_.begin() + from_index); |
228 snapshots_.insert(snapshots_.begin() + to_index, node); | 229 snapshots_.insert(snapshots_.begin() + to_index, node); |
229 | 230 |
230 RenumberSnapshots(std::min(to_index, from_index)); | 231 RenumberSnapshots(std::min(to_index, from_index)); |
231 UpdateSelectedIndex(browser_->selected_index()); | 232 UpdateSelectedIndex(browser_->selected_index()); |
232 } | 233 } |
233 | 234 |
234 void BrowserListener::TabChangedAt( | 235 void BrowserListener::TabChangedAt( |
235 TabContents* contents, | 236 TabContentsWrapper* contents, |
236 int index, | 237 int index, |
237 TabStripModelObserver::TabChangeType change_type) { | 238 TabStripModelObserver::TabChangeType change_type) { |
238 if (change_type != TabStripModelObserver::LOADING_ONLY) { | 239 if (change_type != TabStripModelObserver::LOADING_ONLY) { |
239 snapshots_[index].title->SetTitle(contents->GetTitle()); | 240 snapshots_[index].title->SetTitle(contents->tab_contents()->GetTitle()); |
240 snapshots_[index].title->SetUrl(contents->GetURL()); | 241 snapshots_[index].title->SetUrl(contents->tab_contents()->GetURL()); |
241 snapshots_[index].fav_icon->SetFavIcon(contents->GetFavIcon()); | 242 snapshots_[index].fav_icon->SetFavIcon( |
| 243 contents->tab_contents()->GetFavIcon()); |
242 if (change_type != TabStripModelObserver::TITLE_NOT_LOADING) | 244 if (change_type != TabStripModelObserver::TITLE_NOT_LOADING) |
243 ReloadSnapshot(index); | 245 ReloadSnapshot(index); |
244 } | 246 } |
245 } | 247 } |
246 | 248 |
247 void BrowserListener::TabStripEmpty() { | 249 void BrowserListener::TabStripEmpty() { |
248 snapshots_.clear(); | 250 snapshots_.clear(); |
249 } | 251 } |
250 | 252 |
251 void BrowserListener::TabSelectedAt(TabContents* old_contents, | 253 void BrowserListener::TabSelectedAt(TabContentsWrapper* old_contents, |
252 TabContents* new_contents, | 254 TabContentsWrapper* new_contents, |
253 int index, | 255 int index, |
254 bool user_gesture) { | 256 bool user_gesture) { |
255 UpdateSelectedIndex(index); | 257 UpdateSelectedIndex(index); |
256 } | 258 } |
257 | 259 |
258 void BrowserListener::ReloadSnapshot(int index) { | 260 void BrowserListener::ReloadSnapshot(int index) { |
259 snapshots_[index].snapshot->reload_snapshot(); | 261 snapshots_[index].snapshot->reload_snapshot(); |
260 controller_->StartDelayTimer(); | 262 controller_->StartDelayTimer(); |
261 } | 263 } |
262 | 264 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 if (item.get() == NULL) { | 674 if (item.get() == NULL) { |
673 item = BrowserListenerVector::value_type( | 675 item = BrowserListenerVector::value_type( |
674 new BrowserListener(*iterator, this)); | 676 new BrowserListener(*iterator, this)); |
675 } | 677 } |
676 listeners_.push_back(item); | 678 listeners_.push_back(item); |
677 ++iterator; | 679 ++iterator; |
678 } | 680 } |
679 } | 681 } |
680 | 682 |
681 } // namespace chromeos | 683 } // namespace chromeos |
OLD | NEW |