| 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/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 view_->layer()->SetOpacity(1.0f); | 355 view_->layer()->SetOpacity(1.0f); |
| 356 } | 356 } |
| 357 | 357 |
| 358 private: | 358 private: |
| 359 ShelfView* shelf_view_; | 359 ShelfView* shelf_view_; |
| 360 views::View* view_; | 360 views::View* view_; |
| 361 | 361 |
| 362 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); | 362 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); |
| 363 }; | 363 }; |
| 364 | 364 |
| 365 ShelfView::ShelfView(ShelfModel* model, ShelfDelegate* delegate, Shelf* shelf) | 365 ShelfView::ShelfView(ShelfModel* model, |
| 366 ShelfDelegate* delegate, |
| 367 WmShelf* wm_shelf, |
| 368 Shelf* shelf) |
| 366 : model_(model), | 369 : model_(model), |
| 367 delegate_(delegate), | 370 delegate_(delegate), |
| 371 wm_shelf_(wm_shelf), |
| 368 shelf_(shelf), | 372 shelf_(shelf), |
| 369 view_model_(new views::ViewModel), | 373 view_model_(new views::ViewModel), |
| 370 first_visible_index_(0), | 374 first_visible_index_(0), |
| 371 last_visible_index_(-1), | 375 last_visible_index_(-1), |
| 372 overflow_button_(nullptr), | 376 overflow_button_(nullptr), |
| 373 owner_overflow_bubble_(nullptr), | 377 owner_overflow_bubble_(nullptr), |
| 374 tooltip_(this), | 378 tooltip_(this), |
| 375 drag_pointer_(NONE), | 379 drag_pointer_(NONE), |
| 376 drag_view_(nullptr), | 380 drag_view_(nullptr), |
| 377 start_drag_index_(-1), | 381 start_drag_index_(-1), |
| 378 context_menu_id_(0), | 382 context_menu_id_(0), |
| 379 leading_inset_(kDefaultLeadingInset), | 383 leading_inset_(kDefaultLeadingInset), |
| 380 cancelling_drag_model_changed_(false), | 384 cancelling_drag_model_changed_(false), |
| 381 last_hidden_index_(0), | 385 last_hidden_index_(0), |
| 382 closing_event_time_(base::TimeDelta()), | 386 closing_event_time_(base::TimeDelta()), |
| 383 got_deleted_(nullptr), | 387 got_deleted_(nullptr), |
| 384 drag_and_drop_item_pinned_(false), | 388 drag_and_drop_item_pinned_(false), |
| 385 drag_and_drop_shelf_id_(0), | 389 drag_and_drop_shelf_id_(0), |
| 386 drag_replaced_view_(nullptr), | 390 drag_replaced_view_(nullptr), |
| 387 dragged_off_shelf_(false), | 391 dragged_off_shelf_(false), |
| 388 snap_back_from_rip_off_view_(nullptr), | 392 snap_back_from_rip_off_view_(nullptr), |
| 389 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), | 393 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), |
| 390 overflow_mode_(false), | 394 overflow_mode_(false), |
| 391 main_shelf_(nullptr), | 395 main_shelf_(nullptr), |
| 392 dragged_off_from_overflow_to_shelf_(false), | 396 dragged_off_from_overflow_to_shelf_(false), |
| 393 is_repost_event_(false), | 397 is_repost_event_(false), |
| 394 last_pressed_index_(-1) { | 398 last_pressed_index_(-1) { |
| 395 DCHECK(model_); | 399 DCHECK(model_); |
| 400 DCHECK(wm_shelf_); |
| 396 bounds_animator_.reset(new views::BoundsAnimator(this)); | 401 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 397 bounds_animator_->AddObserver(this); | 402 bounds_animator_->AddObserver(this); |
| 398 set_context_menu_controller(this); | 403 set_context_menu_controller(this); |
| 399 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); | 404 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); |
| 400 } | 405 } |
| 401 | 406 |
| 402 ShelfView::~ShelfView() { | 407 ShelfView::~ShelfView() { |
| 403 bounds_animator_->RemoveObserver(this); | 408 bounds_animator_->RemoveObserver(this); |
| 404 model_->RemoveObserver(this); | 409 model_->RemoveObserver(this); |
| 405 // If we are inside the MenuRunner, we need to know if we were getting | 410 // If we are inside the MenuRunner, we need to know if we were getting |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 | 1353 |
| 1349 void ShelfView::ToggleOverflowBubble() { | 1354 void ShelfView::ToggleOverflowBubble() { |
| 1350 if (IsShowingOverflowBubble()) { | 1355 if (IsShowingOverflowBubble()) { |
| 1351 overflow_bubble_->Hide(); | 1356 overflow_bubble_->Hide(); |
| 1352 return; | 1357 return; |
| 1353 } | 1358 } |
| 1354 | 1359 |
| 1355 if (!overflow_bubble_) | 1360 if (!overflow_bubble_) |
| 1356 overflow_bubble_.reset(new OverflowBubble()); | 1361 overflow_bubble_.reset(new OverflowBubble()); |
| 1357 | 1362 |
| 1358 ShelfView* overflow_view = new ShelfView(model_, delegate_, shelf_); | 1363 ShelfView* overflow_view = |
| 1364 new ShelfView(model_, delegate_, wm_shelf_, shelf_); |
| 1359 overflow_view->overflow_mode_ = true; | 1365 overflow_view->overflow_mode_ = true; |
| 1360 overflow_view->Init(); | 1366 overflow_view->Init(); |
| 1361 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); | 1367 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); |
| 1362 overflow_view->OnShelfAlignmentChanged(); | 1368 overflow_view->OnShelfAlignmentChanged(); |
| 1363 overflow_view->main_shelf_ = this; | 1369 overflow_view->main_shelf_ = this; |
| 1364 UpdateOverflowRange(overflow_view); | 1370 UpdateOverflowRange(overflow_view); |
| 1365 | 1371 |
| 1366 overflow_bubble_->Show(overflow_button_, overflow_view); | 1372 overflow_bubble_->Show(overflow_button_, overflow_view); |
| 1367 | 1373 |
| 1368 Shell::GetInstance()->UpdateShelfVisibility(); | 1374 Shell::GetInstance()->UpdateShelfVisibility(); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 void ShelfView::ShowContextMenuForView(views::View* source, | 1774 void ShelfView::ShowContextMenuForView(views::View* source, |
| 1769 const gfx::Point& point, | 1775 const gfx::Point& point, |
| 1770 ui::MenuSourceType source_type) { | 1776 ui::MenuSourceType source_type) { |
| 1771 const ShelfItem* item = ShelfItemForView(source); | 1777 const ShelfItem* item = ShelfItemForView(source); |
| 1772 if (!item) { | 1778 if (!item) { |
| 1773 Shell::GetInstance()->ShowContextMenu(point, source_type); | 1779 Shell::GetInstance()->ShowContextMenu(point, source_type); |
| 1774 return; | 1780 return; |
| 1775 } | 1781 } |
| 1776 | 1782 |
| 1777 std::unique_ptr<ui::MenuModel> context_menu_model( | 1783 std::unique_ptr<ui::MenuModel> context_menu_model( |
| 1778 Shell::GetInstance()->delegate()->CreateContextMenu(shelf_, item)); | 1784 Shell::GetInstance()->delegate()->CreateContextMenu(wm_shelf_, item)); |
| 1779 if (!context_menu_model) | 1785 if (!context_menu_model) |
| 1780 return; | 1786 return; |
| 1781 | 1787 |
| 1782 context_menu_id_ = item ? item->id : 0; | 1788 context_menu_id_ = item ? item->id : 0; |
| 1783 ShowMenu(context_menu_model.get(), source, point, true, source_type); | 1789 ShowMenu(context_menu_model.get(), source, point, true, source_type); |
| 1784 } | 1790 } |
| 1785 | 1791 |
| 1786 void ShelfView::ShowMenu(ui::MenuModel* menu_model, | 1792 void ShelfView::ShowMenu(ui::MenuModel* menu_model, |
| 1787 views::View* source, | 1793 views::View* source, |
| 1788 const gfx::Point& click_point, | 1794 const gfx::Point& click_point, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 | 1897 |
| 1892 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1898 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 1893 const gfx::Rect bounds = GetBoundsInScreen(); | 1899 const gfx::Rect bounds = GetBoundsInScreen(); |
| 1894 int distance = shelf_->SelectValueForShelfAlignment( | 1900 int distance = shelf_->SelectValueForShelfAlignment( |
| 1895 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1901 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
| 1896 bounds.x() - coordinate.x()); | 1902 bounds.x() - coordinate.x()); |
| 1897 return distance > 0 ? distance : 0; | 1903 return distance > 0 ? distance : 0; |
| 1898 } | 1904 } |
| 1899 | 1905 |
| 1900 } // namespace ash | 1906 } // namespace ash |
| OLD | NEW |