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/tabs/tab_overview_controller.h" | 5 #include "chrome/browser/views/tabs/tab_overview_controller.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/gtk/browser_window_gtk.h" | 9 #include "chrome/browser/gtk/browser_window_gtk.h" |
10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
11 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 11 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
12 #include "chrome/browser/views/tabs/tab_overview_cell.h" | 12 #include "chrome/browser/views/tabs/tab_overview_cell.h" |
13 #include "chrome/browser/views/tabs/tab_overview_container.h" | 13 #include "chrome/browser/views/tabs/tab_overview_container.h" |
| 14 #include "chrome/browser/views/tabs/tab_overview_drag_controller.h" |
14 #include "chrome/browser/views/tabs/tab_overview_grid.h" | 15 #include "chrome/browser/views/tabs/tab_overview_grid.h" |
15 #include "chrome/browser/views/tabs/tab_overview_types.h" | 16 #include "chrome/browser/views/tabs/tab_overview_types.h" |
16 #include "chrome/browser/window_sizer.h" | 17 #include "chrome/browser/window_sizer.h" |
17 #include "views/widget/root_view.h" | 18 #include "views/widget/root_view.h" |
18 #include "views/widget/widget_gtk.h" | 19 #include "views/widget/widget_gtk.h" |
19 | 20 |
20 // Horizontal padding from the edge of the monitor to the overview. | 21 // Horizontal padding from the edge of the monitor to the overview. |
21 static int kMonitorPadding = 20; | 22 static int kMonitorPadding = 20; |
22 // Vertical padding between the overview and the windows along on the bottom. | 23 // Vertical padding between the overview and the windows along on the bottom. |
23 static int kWindowToOverviewPadding = 25; | 24 static int kWindowToOverviewPadding = 25; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 79 } |
79 | 80 |
80 void TabOverviewController::SetBrowser(Browser* browser, | 81 void TabOverviewController::SetBrowser(Browser* browser, |
81 int horizontal_center) { | 82 int horizontal_center) { |
82 horizontal_center_ = horizontal_center; | 83 horizontal_center_ = horizontal_center; |
83 if (browser_) | 84 if (browser_) |
84 model()->RemoveObserver(this); | 85 model()->RemoveObserver(this); |
85 browser_ = browser; | 86 browser_ = browser; |
86 if (browser_) | 87 if (browser_) |
87 model()->AddObserver(this); | 88 model()->AddObserver(this); |
| 89 |
| 90 show_thumbnails_ = false; |
| 91 StartDelayTimer(); |
| 92 |
88 gfx::Rect host_bounds = CalculateHostBounds(); | 93 gfx::Rect host_bounds = CalculateHostBounds(); |
89 if (moved_offscreen_ && model() && model()->count()) { | 94 if (moved_offscreen_ && model() && model()->count()) { |
90 // Need to reset the bounds if we were offscreen. | 95 // Need to reset the bounds if we were offscreen. |
91 host_->SetBounds(host_bounds); | 96 host_->SetBounds(host_bounds); |
92 moved_offscreen_ = false; | 97 moved_offscreen_ = false; |
| 98 } else if (!model() && shown_) { |
| 99 MoveOffscreen(); |
93 } | 100 } |
| 101 if (!moved_offscreen_) |
| 102 container_->SchedulePaint(); |
| 103 |
94 RecreateCells(); | 104 RecreateCells(); |
95 | 105 |
96 container_->set_arrow_center(horizontal_center_ - host_bounds.x()); | 106 container_->set_arrow_center(horizontal_center_ - host_bounds.x()); |
| 107 |
| 108 if (!moved_offscreen_) |
| 109 container_->SchedulePaint(); |
97 } | 110 } |
98 | 111 |
99 TabStripModel* TabOverviewController::model() const { | 112 TabStripModel* TabOverviewController::model() const { |
100 return browser_ ? browser_->tabstrip_model() : NULL; | 113 return browser_ ? browser_->tabstrip_model() : NULL; |
101 } | 114 } |
102 | 115 |
| 116 void TabOverviewController::SetMouseOverMiniWindow(bool over_mini_window) { |
| 117 if (grid_->drag_controller()) |
| 118 grid_->drag_controller()->set_mouse_over_mini_window(over_mini_window); |
| 119 } |
| 120 |
103 void TabOverviewController::Show() { | 121 void TabOverviewController::Show() { |
104 if (host_->IsVisible()) | 122 if (host_->IsVisible()) |
105 return; | 123 return; |
106 | 124 |
107 shown_ = true; | 125 shown_ = true; |
108 DCHECK(model()); // The model needs to be set before showing. | 126 DCHECK(model()); // The model needs to be set before showing. |
109 host_->Show(); | 127 host_->Show(); |
110 delay_timer_.Start( | 128 |
111 base::TimeDelta::FromMilliseconds(350), this, | 129 show_thumbnails_ = false; |
112 &TabOverviewController::StartConfiguring); | 130 StartDelayTimer(); |
113 } | 131 } |
114 | 132 |
115 void TabOverviewController::ConfigureCell(TabOverviewCell* cell, | 133 void TabOverviewController::ConfigureCell(TabOverviewCell* cell, |
116 TabContents* contents) { | 134 TabContents* contents) { |
117 if (contents) { | 135 if (contents) { |
118 cell->SetTitle(contents->GetTitle()); | 136 cell->SetTitle(contents->GetTitle()); |
119 cell->SetFavIcon(contents->GetFavIcon()); | 137 cell->SetFavIcon(contents->GetFavIcon()); |
120 | 138 |
121 if (show_thumbnails_) { | 139 if (show_thumbnails_) { |
122 ThumbnailGenerator* generator = | 140 ThumbnailGenerator* generator = |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 int max_height = static_cast<int>(monitor_bounds_.height() * | 332 int max_height = static_cast<int>(monitor_bounds_.height() * |
315 kOverviewHeight); | 333 kOverviewHeight); |
316 return gfx::Rect(monitor_bounds_.x() + kMonitorPadding, | 334 return gfx::Rect(monitor_bounds_.x() + kMonitorPadding, |
317 monitor_bounds_.bottom() - window_height - | 335 monitor_bounds_.bottom() - window_height - |
318 kWindowToOverviewPadding - max_height, max_width, | 336 kWindowToOverviewPadding - max_height, max_width, |
319 max_height); | 337 max_height); |
320 } | 338 } |
321 | 339 |
322 void TabOverviewController::StartConfiguring() { | 340 void TabOverviewController::StartConfiguring() { |
323 show_thumbnails_ = true; | 341 show_thumbnails_ = true; |
| 342 configure_timer_.Stop(); |
324 configure_timer_.Start( | 343 configure_timer_.Start( |
325 base::TimeDelta::FromMilliseconds(10), this, | 344 base::TimeDelta::FromMilliseconds(10), this, |
326 &TabOverviewController::ConfigureNextUnconfiguredCell); | 345 &TabOverviewController::ConfigureNextUnconfiguredCell); |
327 } | 346 } |
328 | 347 |
329 void TabOverviewController::ConfigureNextUnconfiguredCell() { | 348 void TabOverviewController::ConfigureNextUnconfiguredCell() { |
330 for (int i = 0; i < grid_->GetChildViewCount(); ++i) { | 349 for (int i = 0; i < grid_->GetChildViewCount(); ++i) { |
331 TabOverviewCell* cell = grid_->GetTabOverviewCellAt(i); | 350 TabOverviewCell* cell = grid_->GetTabOverviewCellAt(i); |
332 if (!cell->configured_thumbnail()) { | 351 if (!cell->configured_thumbnail()) { |
333 ConfigureCell(cell, i); | 352 ConfigureCell(cell, i); |
334 return; | 353 return; |
335 } | 354 } |
336 } | 355 } |
337 configure_timer_.Stop(); | 356 configure_timer_.Stop(); |
338 } | 357 } |
| 358 |
| 359 void TabOverviewController::StartDelayTimer() { |
| 360 configure_timer_.Stop(); |
| 361 delay_timer_.Stop(); |
| 362 delay_timer_.Start( |
| 363 base::TimeDelta::FromMilliseconds(350), this, |
| 364 &TabOverviewController::StartConfiguring); |
| 365 } |
OLD | NEW |