| 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_drag_controller.h" | 5 #include "chrome/browser/views/tabs/tab_overview_drag_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
| 9 #include "chrome/browser/dock_info.h" | 9 #include "chrome/browser/dock_info.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 10 #include "chrome/browser/tab_contents/tab_contents.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/views/tabs/tab_overview_cell.h" | 13 #include "chrome/browser/views/tabs/tab_overview_cell.h" |
| 13 #include "chrome/browser/views/tabs/tab_overview_controller.h" | 14 #include "chrome/browser/views/tabs/tab_overview_controller.h" |
| 14 #include "chrome/browser/views/tabs/tab_overview_grid.h" | 15 #include "chrome/browser/views/tabs/tab_overview_grid.h" |
| 16 #include "chrome/browser/views/tabs/tab_overview_types.h" |
| 15 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
| 16 #include "views/fill_layout.h" | 18 #include "views/fill_layout.h" |
| 17 #include "views/view.h" | 19 #include "views/view.h" |
| 18 #include "views/widget/root_view.h" | 20 #include "views/widget/root_view.h" |
| 19 #include "views/widget/widget_gtk.h" | 21 #include "views/widget/widget_gtk.h" |
| 20 | 22 |
| 21 TabOverviewDragController::TabOverviewDragController( | 23 TabOverviewDragController::TabOverviewDragController( |
| 22 TabOverviewController* controller) | 24 TabOverviewController* controller) |
| 23 : controller_(controller), | 25 : controller_(controller), |
| 24 original_model_(controller->model()), | 26 original_model_(controller->model()), |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 col = 0; | 257 col = 0; |
| 256 } else if (location.x() >= grid()->width()) { | 258 } else if (location.x() >= grid()->width()) { |
| 257 col = grid()->columns(); | 259 col = grid()->columns(); |
| 258 } else { | 260 } else { |
| 259 col = (location.x() + grid()->cell_width() / 2) / | 261 col = (location.x() + grid()->cell_width() / 2) / |
| 260 (grid()->cell_width() + TabOverviewGrid::kCellXPadding); | 262 (grid()->cell_width() + TabOverviewGrid::kCellXPadding); |
| 261 } | 263 } |
| 262 } | 264 } |
| 263 int new_index = std::min(model()->count() - 1, | 265 int new_index = std::min(model()->count() - 1, |
| 264 row * grid()->columns() + col); | 266 row * grid()->columns() + col); |
| 265 if (detached_tab_ ) { | 267 if (detached_tab_) { |
| 266 // The user dragged a detached tab back over the grid, reattach it. | 268 // The user dragged a detached tab back over the grid, reattach it. |
| 267 Attach(new_index); | 269 Attach(new_index); |
| 268 } else if (new_index != current_index_) { | 270 } else if (new_index != current_index_) { |
| 269 grid()->set_floating_index(new_index); | 271 grid()->set_floating_index(new_index); |
| 270 modifying_model_ = true; | 272 modifying_model_ = true; |
| 271 model()->MoveTabContentsAt(current_index_, new_index, false); | 273 model()->MoveTabContentsAt(current_index_, new_index, false); |
| 272 modifying_model_ = false; | 274 modifying_model_ = false; |
| 273 current_index_ = new_index; | 275 current_index_ = new_index; |
| 274 } | 276 } |
| 275 gfx::Rect target_bounds = grid()->CellBounds(current_index_); | 277 gfx::Rect target_bounds = grid()->CellBounds(current_index_); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 gfx::Point screen_loc = location; | 365 gfx::Point screen_loc = location; |
| 364 screen_loc.Offset(-x_offset_, -y_offset_); | 366 screen_loc.Offset(-x_offset_, -y_offset_); |
| 365 grid()->ConvertPointToScreen(grid(), &screen_loc); | 367 grid()->ConvertPointToScreen(grid(), &screen_loc); |
| 366 TabOverviewCell* cell = new TabOverviewCell(); | 368 TabOverviewCell* cell = new TabOverviewCell(); |
| 367 cell->set_preferred_size( | 369 cell->set_preferred_size( |
| 368 gfx::Size(grid()->cell_width(), grid()->cell_height())); | 370 gfx::Size(grid()->cell_width(), grid()->cell_height())); |
| 369 controller_->ConfigureCell(cell, tab_contents); | 371 controller_->ConfigureCell(cell, tab_contents); |
| 370 widget->Init(NULL, gfx::Rect(screen_loc, cell->GetPreferredSize()), true); | 372 widget->Init(NULL, gfx::Rect(screen_loc, cell->GetPreferredSize()), true); |
| 371 widget->GetRootView()->SetLayoutManager(new views::FillLayout()); | 373 widget->GetRootView()->SetLayoutManager(new views::FillLayout()); |
| 372 widget->GetRootView()->AddChildView(cell); | 374 widget->GetRootView()->AddChildView(cell); |
| 375 |
| 376 std::vector<int> params(4); |
| 377 params[0] = screen_loc.x() + x_offset_; |
| 378 params[1] = screen_loc.y() + y_offset_; |
| 379 params[2] = x_offset_; |
| 380 params[3] = y_offset_; |
| 381 TabOverviewTypes::instance()->SetWindowType( |
| 382 widget->GetNativeView(), |
| 383 TabOverviewTypes::WINDOW_TYPE_CHROME_FLOATING_TAB, |
| 384 ¶ms); |
| 385 |
| 373 return widget; | 386 return widget; |
| 374 } | 387 } |
| 375 | 388 |
| 376 void TabOverviewDragController::SetDetachedContents(TabContents* tab) { | 389 void TabOverviewDragController::SetDetachedContents(TabContents* tab) { |
| 377 if (detached_tab_) { | 390 if (detached_tab_) { |
| 378 registrar_.Remove(this, | 391 registrar_.Remove(this, |
| 379 NotificationType::TAB_CONTENTS_DESTROYED, | 392 NotificationType::TAB_CONTENTS_DESTROYED, |
| 380 Source<TabContents>(detached_tab_)); | 393 Source<TabContents>(detached_tab_)); |
| 381 if (detached_tab_->delegate() == this) | 394 if (detached_tab_->delegate() == this) |
| 382 detached_tab_->set_delegate(original_delegate_); | 395 detached_tab_->set_delegate(original_delegate_); |
| 383 else | 396 else |
| 384 DLOG(WARNING) << " delegate changed"; | 397 DLOG(WARNING) << " delegate changed"; |
| 385 } | 398 } |
| 386 original_delegate_ = NULL; | 399 original_delegate_ = NULL; |
| 387 detached_tab_ = tab; | 400 detached_tab_ = tab; |
| 388 if (tab) { | 401 if (tab) { |
| 389 registrar_.Add(this, | 402 registrar_.Add(this, |
| 390 NotificationType::TAB_CONTENTS_DESTROYED, | 403 NotificationType::TAB_CONTENTS_DESTROYED, |
| 391 Source<TabContents>(tab)); | 404 Source<TabContents>(tab)); |
| 392 | 405 |
| 393 // We need to be the delegate so we receive messages about stuff, | 406 // We need to be the delegate so we receive messages about stuff, |
| 394 // otherwise our dragged contents may be replaced and subsequently | 407 // otherwise our dragged contents may be replaced and subsequently |
| 395 // collected/destroyed while the drag is in process, leading to | 408 // collected/destroyed while the drag is in process, leading to |
| 396 // nasty crashes. | 409 // nasty crashes. |
| 397 original_delegate_ = tab->delegate(); | 410 original_delegate_ = tab->delegate(); |
| 398 tab->set_delegate(this); | 411 tab->set_delegate(this); |
| 399 } | 412 } |
| 400 } | 413 } |
| OLD | NEW |