| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
| 11 #include "ash/common/ash_constants.h" | 11 #include "ash/common/ash_constants.h" |
| 12 #include "ash/common/ash_switches.h" | 12 #include "ash/common/ash_switches.h" |
| 13 #include "ash/common/shelf/app_list_button.h" | 13 #include "ash/common/shelf/app_list_button.h" |
| 14 #include "ash/common/shelf/overflow_bubble.h" | 14 #include "ash/common/shelf/overflow_bubble.h" |
| 15 #include "ash/common/shelf/overflow_bubble_view.h" | 15 #include "ash/common/shelf/overflow_bubble_view.h" |
| 16 #include "ash/common/shelf/overflow_button.h" | 16 #include "ash/common/shelf/overflow_button.h" |
| 17 #include "ash/common/shelf/shelf_background_animator.h" |
| 17 #include "ash/common/shelf/shelf_constants.h" | 18 #include "ash/common/shelf/shelf_constants.h" |
| 18 #include "ash/common/shelf/shelf_delegate.h" | 19 #include "ash/common/shelf/shelf_delegate.h" |
| 19 #include "ash/common/shelf/shelf_menu_model.h" | 20 #include "ash/common/shelf/shelf_menu_model.h" |
| 20 #include "ash/common/shelf/shelf_model.h" | 21 #include "ash/common/shelf/shelf_model.h" |
| 21 #include "ash/common/shell_delegate.h" | 22 #include "ash/common/shell_delegate.h" |
| 22 #include "ash/common/wm/root_window_finder.h" | 23 #include "ash/common/wm/root_window_finder.h" |
| 23 #include "ash/common/wm_shell.h" | 24 #include "ash/common/wm_shell.h" |
| 24 #include "ash/drag_drop/drag_image_view.h" | 25 #include "ash/drag_drop/drag_image_view.h" |
| 25 #include "ash/scoped_target_root_window.h" | 26 #include "ash/scoped_target_root_window.h" |
| 26 #include "ash/shelf/shelf.h" | 27 #include "ash/shelf/shelf.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 354 |
| 354 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); | 355 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); |
| 355 }; | 356 }; |
| 356 | 357 |
| 357 // static | 358 // static |
| 358 const int ShelfView::kMinimumDragDistance = 8; | 359 const int ShelfView::kMinimumDragDistance = 8; |
| 359 | 360 |
| 360 ShelfView::ShelfView(ShelfModel* model, | 361 ShelfView::ShelfView(ShelfModel* model, |
| 361 ShelfDelegate* delegate, | 362 ShelfDelegate* delegate, |
| 362 WmShelf* wm_shelf, | 363 WmShelf* wm_shelf, |
| 363 Shelf* shelf) | 364 Shelf* shelf, |
| 365 ShelfBackgroundAnimator* background_animator) |
| 364 : model_(model), | 366 : model_(model), |
| 365 delegate_(delegate), | 367 delegate_(delegate), |
| 366 wm_shelf_(wm_shelf), | 368 wm_shelf_(wm_shelf), |
| 367 shelf_(shelf), | 369 shelf_(shelf), |
| 368 view_model_(new views::ViewModel), | 370 view_model_(new views::ViewModel), |
| 369 first_visible_index_(0), | 371 first_visible_index_(0), |
| 370 last_visible_index_(-1), | 372 last_visible_index_(-1), |
| 371 overflow_button_(nullptr), | 373 overflow_button_(nullptr), |
| 372 owner_overflow_bubble_(nullptr), | 374 owner_overflow_bubble_(nullptr), |
| 373 tooltip_(this), | 375 tooltip_(this), |
| 374 drag_pointer_(NONE), | 376 drag_pointer_(NONE), |
| 375 drag_view_(nullptr), | 377 drag_view_(nullptr), |
| 376 start_drag_index_(-1), | 378 start_drag_index_(-1), |
| 377 context_menu_id_(0), | 379 context_menu_id_(0), |
| 378 leading_inset_(kDefaultLeadingInset), | 380 leading_inset_(kDefaultLeadingInset), |
| 379 cancelling_drag_model_changed_(false), | 381 cancelling_drag_model_changed_(false), |
| 380 last_hidden_index_(0), | 382 last_hidden_index_(0), |
| 381 closing_event_time_(base::TimeTicks()), | 383 closing_event_time_(base::TimeTicks()), |
| 382 drag_and_drop_item_pinned_(false), | 384 drag_and_drop_item_pinned_(false), |
| 383 drag_and_drop_shelf_id_(0), | 385 drag_and_drop_shelf_id_(0), |
| 384 drag_replaced_view_(nullptr), | 386 drag_replaced_view_(nullptr), |
| 385 dragged_off_shelf_(false), | 387 dragged_off_shelf_(false), |
| 386 snap_back_from_rip_off_view_(nullptr), | 388 snap_back_from_rip_off_view_(nullptr), |
| 387 overflow_mode_(false), | 389 overflow_mode_(false), |
| 388 main_shelf_(nullptr), | 390 main_shelf_(nullptr), |
| 389 dragged_off_from_overflow_to_shelf_(false), | 391 dragged_off_from_overflow_to_shelf_(false), |
| 390 is_repost_event_on_same_item_(false), | 392 is_repost_event_on_same_item_(false), |
| 391 last_pressed_index_(-1) { | 393 last_pressed_index_(-1), |
| 394 background_animator_(background_animator) { |
| 392 DCHECK(model_); | 395 DCHECK(model_); |
| 393 DCHECK(delegate_); | 396 DCHECK(delegate_); |
| 394 DCHECK(wm_shelf_); | 397 DCHECK(wm_shelf_); |
| 395 bounds_animator_.reset(new views::BoundsAnimator(this)); | 398 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 396 bounds_animator_->AddObserver(this); | 399 bounds_animator_->AddObserver(this); |
| 397 set_context_menu_controller(this); | 400 set_context_menu_controller(this); |
| 398 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); | 401 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); |
| 399 } | 402 } |
| 400 | 403 |
| 401 ShelfView::~ShelfView() { | 404 ShelfView::~ShelfView() { |
| 402 bounds_animator_->RemoveObserver(this); | 405 bounds_animator_->RemoveObserver(this); |
| 403 model_->RemoveObserver(this); | 406 model_->RemoveObserver(this); |
| 407 if (background_animator_) |
| 408 background_animator_->RemoveObserver(this); |
| 404 } | 409 } |
| 405 | 410 |
| 406 void ShelfView::Init() { | 411 void ShelfView::Init() { |
| 407 model_->AddObserver(this); | 412 model_->AddObserver(this); |
| 408 | 413 |
| 409 const ShelfItems& items(model_->items()); | 414 const ShelfItems& items(model_->items()); |
| 410 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 415 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
| 411 views::View* child = CreateViewForItem(*i); | 416 views::View* child = CreateViewForItem(*i); |
| 412 child->SetPaintToLayer(true); | 417 child->SetPaintToLayer(true); |
| 413 view_model_->Add(child, static_cast<int>(i - items.begin())); | 418 view_model_->Add(child, static_cast<int>(i - items.begin())); |
| 414 AddChildView(child); | 419 AddChildView(child); |
| 415 } | 420 } |
| 416 overflow_button_ = new OverflowButton(this, wm_shelf_); | 421 overflow_button_ = new OverflowButton(this, wm_shelf_); |
| 417 overflow_button_->set_context_menu_controller(this); | 422 overflow_button_->set_context_menu_controller(this); |
| 418 ConfigureChildView(overflow_button_); | 423 ConfigureChildView(overflow_button_); |
| 419 AddChildView(overflow_button_); | 424 AddChildView(overflow_button_); |
| 420 | 425 |
| 426 if (background_animator_) |
| 427 background_animator_->AddObserver(this); |
| 428 |
| 421 // We'll layout when our bounds change. | 429 // We'll layout when our bounds change. |
| 422 } | 430 } |
| 423 | 431 |
| 424 void ShelfView::OnShelfAlignmentChanged() { | 432 void ShelfView::OnShelfAlignmentChanged() { |
| 425 overflow_button_->OnShelfAlignmentChanged(); | 433 overflow_button_->OnShelfAlignmentChanged(); |
| 426 LayoutToIdealBounds(); | 434 LayoutToIdealBounds(); |
| 427 for (int i = 0; i < view_model_->view_size(); ++i) { | 435 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 428 if (i >= first_visible_index_ && i <= last_visible_index_) | 436 if (i >= first_visible_index_ && i <= last_visible_index_) |
| 429 view_model_->view_at(i)->Layout(); | 437 view_model_->view_at(i)->Layout(); |
| 430 } | 438 } |
| (...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 void ShelfView::ToggleOverflowBubble() { | 1371 void ShelfView::ToggleOverflowBubble() { |
| 1364 if (IsShowingOverflowBubble()) { | 1372 if (IsShowingOverflowBubble()) { |
| 1365 overflow_bubble_->Hide(); | 1373 overflow_bubble_->Hide(); |
| 1366 return; | 1374 return; |
| 1367 } | 1375 } |
| 1368 | 1376 |
| 1369 if (!overflow_bubble_) | 1377 if (!overflow_bubble_) |
| 1370 overflow_bubble_.reset(new OverflowBubble(wm_shelf_)); | 1378 overflow_bubble_.reset(new OverflowBubble(wm_shelf_)); |
| 1371 | 1379 |
| 1372 ShelfView* overflow_view = | 1380 ShelfView* overflow_view = |
| 1373 new ShelfView(model_, delegate_, wm_shelf_, shelf_); | 1381 new ShelfView(model_, delegate_, wm_shelf_, shelf_, nullptr); |
| 1374 overflow_view->overflow_mode_ = true; | 1382 overflow_view->overflow_mode_ = true; |
| 1375 overflow_view->Init(); | 1383 overflow_view->Init(); |
| 1376 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); | 1384 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); |
| 1377 overflow_view->OnShelfAlignmentChanged(); | 1385 overflow_view->OnShelfAlignmentChanged(); |
| 1378 overflow_view->main_shelf_ = this; | 1386 overflow_view->main_shelf_ = this; |
| 1379 UpdateOverflowRange(overflow_view); | 1387 UpdateOverflowRange(overflow_view); |
| 1380 | 1388 |
| 1381 overflow_bubble_->Show(overflow_button_, overflow_view); | 1389 overflow_bubble_->Show(overflow_button_, overflow_view); |
| 1382 | 1390 |
| 1383 Shell::GetInstance()->UpdateShelfVisibility(); | 1391 Shell::GetInstance()->UpdateShelfVisibility(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 } | 1548 } |
| 1541 | 1549 |
| 1542 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { | 1550 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { |
| 1543 aura::Window* target_window = static_cast<views::View*>(event->target()) | 1551 aura::Window* target_window = static_cast<views::View*>(event->target()) |
| 1544 ->GetWidget() | 1552 ->GetWidget() |
| 1545 ->GetNativeWindow(); | 1553 ->GetNativeWindow(); |
| 1546 if (gesture_handler_.ProcessGestureEvent(*event, target_window)) | 1554 if (gesture_handler_.ProcessGestureEvent(*event, target_window)) |
| 1547 event->StopPropagation(); | 1555 event->StopPropagation(); |
| 1548 } | 1556 } |
| 1549 | 1557 |
| 1558 void ShelfView::UpdateShelfItemBackground(int alpha) { |
| 1559 GetAppListButton()->SetBackgroundAlpha(alpha); |
| 1560 overflow_button_->SetBackgroundAlpha(alpha); |
| 1561 } |
| 1562 |
| 1550 void ShelfView::ShelfItemAdded(int model_index) { | 1563 void ShelfView::ShelfItemAdded(int model_index) { |
| 1551 { | 1564 { |
| 1552 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_, | 1565 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_, |
| 1553 true); | 1566 true); |
| 1554 model_index = CancelDrag(model_index); | 1567 model_index = CancelDrag(model_index); |
| 1555 } | 1568 } |
| 1556 views::View* view = CreateViewForItem(model_->items()[model_index]); | 1569 views::View* view = CreateViewForItem(model_->items()[model_index]); |
| 1557 AddChildView(view); | 1570 AddChildView(view); |
| 1558 // Hide the view, it'll be made visible when the animation is done. Using | 1571 // Hide the view, it'll be made visible when the animation is done. Using |
| 1559 // opacity 0 here to avoid messing with CalculateIdealBounds which touches | 1572 // opacity 0 here to avoid messing with CalculateIdealBounds which touches |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 | 1920 |
| 1908 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1921 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1909 const gfx::Rect bounds = GetBoundsInScreen(); | 1922 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1910 int distance = shelf_->SelectValueForShelfAlignment( | 1923 int distance = shelf_->SelectValueForShelfAlignment( |
| 1911 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1924 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1912 bounds.x() - coordinate.x()); | 1925 bounds.x() - coordinate.x()); |
| 1913 return distance > 0 ? distance : 0; | 1926 return distance > 0 ? distance : 0; |
| 1914 } | 1927 } |
| 1915 | 1928 |
| 1916 } // namespace ash | 1929 } // namespace ash |
| OLD | NEW |