| 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/gtk/browser_window_gtk.h" | 8 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" | 9 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 #include "chrome/browser/views/tabs/tab_overview_cell.h" | 10 #include "chrome/browser/views/tabs/tab_overview_cell.h" |
| 11 #include "chrome/browser/views/tabs/tab_overview_container.h" | 11 #include "chrome/browser/views/tabs/tab_overview_container.h" |
| 12 #include "chrome/browser/views/tabs/tab_overview_grid.h" | 12 #include "chrome/browser/views/tabs/tab_overview_grid.h" |
| 13 #include "chrome/browser/views/tabs/tab_overview_types.h" | 13 #include "chrome/browser/views/tabs/tab_overview_types.h" |
| 14 #include "chrome/browser/window_sizer.h" | 14 #include "chrome/browser/window_sizer.h" |
| 15 #include "views/fill_layout.h" | |
| 16 #include "views/widget/root_view.h" | 15 #include "views/widget/root_view.h" |
| 17 #include "views/widget/widget_gtk.h" | 16 #include "views/widget/widget_gtk.h" |
| 18 | 17 |
| 19 // Horizontal padding from the edge of the monitor to the overview. | 18 // Horizontal padding from the edge of the monitor to the overview. |
| 20 static int kMonitorPadding = 20; | 19 static int kMonitorPadding = 20; |
| 21 // Vertical padding between the overview and the windows along on the bottom. | 20 // Vertical padding between the overview and the windows along on the bottom. |
| 22 static int kWindowToOverviewPadding = 25; | 21 static int kWindowToOverviewPadding = 25; |
| 23 // Height of the windows along the bottom, as a percentage of the monitors | 22 // Height of the windows along the bottom, as a percentage of the monitors |
| 24 // height. | 23 // height. |
| 25 static float kWindowHeight = .30; | 24 static float kWindowHeight = .30; |
| 26 // Height of the tab overview, as a percentage of monitors height. | 25 // Height of the tab overview, as a percentage of monitors height. |
| 27 static float kOverviewHeight = .55; | 26 static float kOverviewHeight = .55; |
| 28 | 27 |
| 29 TabOverviewController::TabOverviewController( | 28 TabOverviewController::TabOverviewController( |
| 30 const gfx::Point& monitor_origin) | 29 const gfx::Point& monitor_origin) |
| 31 : host_(NULL), | 30 : host_(NULL), |
| 32 container_(NULL), | 31 container_(NULL), |
| 33 grid_(NULL), | 32 grid_(NULL), |
| 34 browser_(NULL), | 33 browser_(NULL), |
| 35 drag_browser_(NULL), | 34 drag_browser_(NULL), |
| 36 moved_offscreen_(false), | 35 moved_offscreen_(false), |
| 37 shown_(false), | 36 shown_(false), |
| 38 horizontal_center_(0), | 37 horizontal_center_(0), |
| 39 change_window_bounds_on_animate_(false), | 38 change_window_bounds_on_animate_(false), |
| 40 mutating_grid_(false) { | 39 mutating_grid_(false) { |
| 41 grid_ = new TabOverviewGrid(this); | 40 grid_ = new TabOverviewGrid(this); |
| 42 | 41 |
| 42 // Determine the max size for the overview. |
| 43 scoped_ptr<WindowSizer::MonitorInfoProvider> provider( |
| 44 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 45 monitor_bounds_ = provider->GetMonitorWorkAreaMatching( |
| 46 gfx::Rect(monitor_origin.x(), monitor_origin.y(), 1, 1)); |
| 47 |
| 43 // Create the host. | 48 // Create the host. |
| 44 views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP); | 49 views::WidgetGtk* host = new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP); |
| 45 host->set_delete_on_destroy(false); | 50 host->set_delete_on_destroy(false); |
| 46 host->MakeTransparent(); | 51 host->MakeTransparent(); |
| 47 host->Init(NULL, gfx::Rect(), true); | 52 host->Init(NULL, CalculateHostBounds(), true); |
| 48 TabOverviewTypes::instance()->SetWindowType( | 53 TabOverviewTypes::instance()->SetWindowType( |
| 49 host->GetNativeView(), | 54 host->GetNativeView(), |
| 50 TabOverviewTypes::WINDOW_TYPE_CHROME_TAB_SUMMARY, | 55 TabOverviewTypes::WINDOW_TYPE_CHROME_TAB_SUMMARY, |
| 51 NULL); | 56 NULL); |
| 52 host_ = host; | 57 host_ = host; |
| 53 | 58 |
| 54 container_ = new TabOverviewContainer(); | 59 container_ = new TabOverviewContainer(); |
| 55 container_->AddChildView(grid_); | 60 container_->AddChildView(grid_); |
| 56 host->GetRootView()->SetLayoutManager(new views::FillLayout()); | |
| 57 host->GetRootView()->AddChildView(container_); | 61 host->GetRootView()->AddChildView(container_); |
| 58 | 62 |
| 59 // Determine the max size for the overview. | 63 container_->SetMaxSize(CalculateHostBounds().size()); |
| 60 scoped_ptr<WindowSizer::MonitorInfoProvider> provider( | |
| 61 WindowSizer::CreateDefaultMonitorInfoProvider()); | |
| 62 monitor_bounds_ = provider->GetMonitorWorkAreaMatching( | |
| 63 gfx::Rect(monitor_origin.x(), monitor_origin.y(), 1, 1)); | |
| 64 monitor_bounds_.Inset(kMonitorPadding, 0); | |
| 65 int max_width = monitor_bounds_.width(); | |
| 66 int max_height = static_cast<int>(monitor_bounds_.height() * | |
| 67 kOverviewHeight); | |
| 68 container_->SetMaxSize(gfx::Size(max_width, max_height)); | |
| 69 | 64 |
| 70 // TODO: remove this when we get mid point. | 65 // TODO: remove this when we get mid point. |
| 71 horizontal_center_ = monitor_bounds_.x() + monitor_bounds_.width() / 2; | 66 horizontal_center_ = monitor_bounds_.x() + monitor_bounds_.width() / 2; |
| 72 } | 67 } |
| 73 | 68 |
| 74 TabOverviewController::~TabOverviewController() { | 69 TabOverviewController::~TabOverviewController() { |
| 75 if (browser_) | 70 if (browser_) |
| 76 model()->RemoveObserver(this); | 71 model()->RemoveObserver(this); |
| 77 host_->Close(); | 72 host_->Close(); |
| 78 // The drag controller may call back to us from it's destructor. Make sure | 73 // The drag controller may call back to us from it's destructor. Make sure |
| 79 // it's destroyed before us. | 74 // it's destroyed before us. |
| 80 grid()->CancelDrag(); | 75 grid()->CancelDrag(); |
| 81 } | 76 } |
| 82 | 77 |
| 83 void TabOverviewController::SetBrowser(Browser* browser, | 78 void TabOverviewController::SetBrowser(Browser* browser, |
| 84 int horizontal_center) { | 79 int horizontal_center) { |
| 85 // TODO: update this when we horizontal_center is correct. | 80 // TODO: update this when we horizontal_center is correct. |
| 86 // horizontal_center_ = horizontal_center; | 81 // horizontal_center_ = horizontal_center; |
| 87 if (browser_) | 82 if (browser_) |
| 88 model()->RemoveObserver(this); | 83 model()->RemoveObserver(this); |
| 89 browser_ = browser; | 84 browser_ = browser; |
| 90 if (browser_) | 85 if (browser_) |
| 91 model()->AddObserver(this); | 86 model()->AddObserver(this); |
| 92 moved_offscreen_ = false; | 87 if (moved_offscreen_ && model() && model()->count()) { |
| 88 // Need to reset the bounds if we were offscreen. |
| 89 host_->SetBounds(CalculateHostBounds()); |
| 90 moved_offscreen_ = false; |
| 91 } |
| 93 RecreateCells(); | 92 RecreateCells(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 TabStripModel* TabOverviewController::model() const { | 95 TabStripModel* TabOverviewController::model() const { |
| 97 return browser_ ? browser_->tabstrip_model() : NULL; | 96 return browser_ ? browser_->tabstrip_model() : NULL; |
| 98 } | 97 } |
| 99 | 98 |
| 100 void TabOverviewController::Show() { | 99 void TabOverviewController::Show() { |
| 101 if (host_->IsVisible()) | 100 if (host_->IsVisible()) |
| 102 return; | 101 return; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 140 } |
| 142 | 141 |
| 143 void TabOverviewController::SelectTabContents(TabContents* contents) { | 142 void TabOverviewController::SelectTabContents(TabContents* contents) { |
| 144 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void TabOverviewController::GridAnimationEnded() { | 146 void TabOverviewController::GridAnimationEnded() { |
| 148 if (moved_offscreen_ || !change_window_bounds_on_animate_ || mutating_grid_) | 147 if (moved_offscreen_ || !change_window_bounds_on_animate_ || mutating_grid_) |
| 149 return; | 148 return; |
| 150 | 149 |
| 151 SetHostBounds(target_bounds_); | 150 container_->SetBounds(target_bounds_); |
| 152 grid_->UpdateDragController(); | 151 grid_->UpdateDragController(); |
| 153 change_window_bounds_on_animate_ = false; | 152 change_window_bounds_on_animate_ = false; |
| 154 } | 153 } |
| 155 | 154 |
| 156 void TabOverviewController::GridAnimationProgressed() { | 155 void TabOverviewController::GridAnimationProgressed() { |
| 157 if (moved_offscreen_ || !change_window_bounds_on_animate_) | 156 if (moved_offscreen_ || !change_window_bounds_on_animate_) |
| 158 return; | 157 return; |
| 159 | 158 |
| 160 DCHECK(!mutating_grid_); | 159 DCHECK(!mutating_grid_); |
| 161 | 160 |
| 162 SetHostBounds(grid_->AnimationPosition(start_bounds_, target_bounds_)); | 161 // Schedule a paint before and after changing sizes to deal with the case |
| 162 // of the view shrinking in size. |
| 163 container_->SchedulePaint(); |
| 164 container_->SetBounds( |
| 165 grid_->AnimationPosition(start_bounds_, target_bounds_)); |
| 166 container_->SchedulePaint(); |
| 167 |
| 168 // Update the position of the dragged cell. |
| 163 grid_->UpdateDragController(); | 169 grid_->UpdateDragController(); |
| 164 } | 170 } |
| 165 | 171 |
| 166 void TabOverviewController::GridAnimationCanceled() { | 172 void TabOverviewController::GridAnimationCanceled() { |
| 167 change_window_bounds_on_animate_ = false; | 173 change_window_bounds_on_animate_ = false; |
| 168 } | 174 } |
| 169 | 175 |
| 170 void TabOverviewController::TabInsertedAt(TabContents* contents, | 176 void TabOverviewController::TabInsertedAt(TabContents* contents, |
| 171 int index, | 177 int index, |
| 172 bool foreground) { | 178 bool foreground) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 for (int i = 0; i < model()->count(); ++i) { | 241 for (int i = 0; i < model()->count(); ++i) { |
| 236 TabOverviewCell* child = new TabOverviewCell(); | 242 TabOverviewCell* child = new TabOverviewCell(); |
| 237 ConfigureCell(child, i); | 243 ConfigureCell(child, i); |
| 238 grid_->AddChildView(child); | 244 grid_->AddChildView(child); |
| 239 } | 245 } |
| 240 } | 246 } |
| 241 | 247 |
| 242 if (moved_offscreen_) | 248 if (moved_offscreen_) |
| 243 return; | 249 return; |
| 244 | 250 |
| 245 SetHostBounds(CalculateHostBounds()); | |
| 246 if (grid()->GetChildViewCount() > 0) { | 251 if (grid()->GetChildViewCount() > 0) { |
| 247 if (shown_) | 252 if (shown_) |
| 248 host_->Show(); | 253 host_->Show(); |
| 249 } else { | 254 } else { |
| 250 host_->Hide(); | 255 host_->Hide(); |
| 251 } | 256 } |
| 257 container_->SetBounds(CalculateContainerBounds()); |
| 252 } | 258 } |
| 253 | 259 |
| 254 void TabOverviewController::UpdateStartAndTargetBounds() { | 260 void TabOverviewController::UpdateStartAndTargetBounds() { |
| 255 if (moved_offscreen_ || !shown_) | 261 if (moved_offscreen_ || !shown_) |
| 256 return; | 262 return; |
| 257 | 263 |
| 258 if (grid()->GetChildViewCount() == 0) { | 264 if (grid()->GetChildViewCount() == 0) { |
| 259 host_->Hide(); | 265 host_->Hide(); |
| 260 } else { | 266 } else { |
| 261 host_->GetBounds(&start_bounds_, true); | 267 start_bounds_ = container_->bounds(); |
| 262 target_bounds_ = CalculateHostBounds(); | 268 target_bounds_ = CalculateContainerBounds(); |
| 263 change_window_bounds_on_animate_ = (start_bounds_ != target_bounds_); | 269 change_window_bounds_on_animate_ = (start_bounds_ != target_bounds_); |
| 264 } | 270 } |
| 265 } | 271 } |
| 266 | 272 |
| 267 void TabOverviewController::SetHostBounds(const gfx::Rect& bounds) { | 273 gfx::Rect TabOverviewController::CalculateContainerBounds() { |
| 268 host_->SetBounds(bounds); | 274 gfx::Rect host_bounds = CalculateHostBounds(); |
| 269 container_->UpdateWidgetShape(horizontal_center_, bounds.width(), | 275 const gfx::Size& host_size = CalculateHostBounds().size(); |
| 270 bounds.height()); | 276 gfx::Size pref = container_->GetPreferredSize(); |
| 277 int relative_horizontal_center = horizontal_center_ - host_bounds.x(); |
| 278 int x = relative_horizontal_center - pref.width() / 2; |
| 279 int y = host_size.height() - pref.height(); |
| 280 return gfx::Rect(x, y, pref.width(), pref.height()). |
| 281 AdjustToFit(gfx::Rect(0, 0, host_size.width(), host_size.height())); |
| 271 } | 282 } |
| 272 | 283 |
| 273 gfx::Rect TabOverviewController::CalculateHostBounds() { | 284 gfx::Rect TabOverviewController::CalculateHostBounds() { |
| 274 gfx::Size pref = container_->GetPreferredSize(); | 285 int max_width = monitor_bounds_.width() - kMonitorPadding * 2; |
| 275 int x = horizontal_center_ - pref.width() / 2; | 286 int window_height = monitor_bounds_.height() * kWindowHeight; |
| 276 int y = monitor_bounds_.bottom() - | 287 int max_height = static_cast<int>(monitor_bounds_.height() * |
| 277 static_cast<int>(monitor_bounds_.height() * kWindowHeight) - | 288 kOverviewHeight); |
| 278 kWindowToOverviewPadding - pref.height(); | 289 return gfx::Rect(monitor_bounds_.x() + kMonitorPadding, |
| 279 return gfx::Rect(x, y, pref.width(), pref.height()). | 290 monitor_bounds_.bottom() - window_height - |
| 280 AdjustToFit(monitor_bounds_); | 291 kWindowToOverviewPadding - max_height, max_width, |
| 292 max_height); |
| 281 } | 293 } |
| OLD | NEW |