Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: ash/common/shelf/shelf_view.cc

Issue 2228713003: mash: Convert ShelfView to wm common types, clean up Shelf access (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix control reaches end of non-void function warnings Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/shelf/shelf_view.h ('k') | ash/common/shelf/wm_shelf.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/common/ash_constants.h" 10 #include "ash/common/ash_constants.h"
11 #include "ash/common/ash_switches.h" 11 #include "ash/common/ash_switches.h"
12 #include "ash/common/drag_drop/drag_image_view.h" 12 #include "ash/common/drag_drop/drag_image_view.h"
13 #include "ash/common/scoped_root_window_for_new_windows.h" 13 #include "ash/common/scoped_root_window_for_new_windows.h"
14 #include "ash/common/shelf/app_list_button.h" 14 #include "ash/common/shelf/app_list_button.h"
15 #include "ash/common/shelf/overflow_bubble.h" 15 #include "ash/common/shelf/overflow_bubble.h"
16 #include "ash/common/shelf/overflow_bubble_view.h" 16 #include "ash/common/shelf/overflow_bubble_view.h"
17 #include "ash/common/shelf/overflow_button.h" 17 #include "ash/common/shelf/overflow_button.h"
18 #include "ash/common/shelf/shelf_button.h" 18 #include "ash/common/shelf/shelf_button.h"
19 #include "ash/common/shelf/shelf_constants.h" 19 #include "ash/common/shelf/shelf_constants.h"
20 #include "ash/common/shelf/shelf_delegate.h" 20 #include "ash/common/shelf/shelf_delegate.h"
21 #include "ash/common/shelf/shelf_icon_observer.h"
21 #include "ash/common/shelf/shelf_menu_model.h" 22 #include "ash/common/shelf/shelf_menu_model.h"
22 #include "ash/common/shelf/shelf_model.h" 23 #include "ash/common/shelf/shelf_model.h"
23 #include "ash/common/shelf/wm_shelf.h" 24 #include "ash/common/shelf/wm_shelf.h"
24 #include "ash/common/shell_delegate.h" 25 #include "ash/common/shell_delegate.h"
25 #include "ash/common/wm/root_window_finder.h" 26 #include "ash/common/wm/root_window_finder.h"
26 #include "ash/common/wm_lookup.h" 27 #include "ash/common/wm_lookup.h"
27 #include "ash/common/wm_shell.h" 28 #include "ash/common/wm_shell.h"
28 #include "ash/common/wm_window.h" 29 #include "ash/common/wm_window.h"
29 #include "ash/shelf/shelf.h"
30 #include "ash/shelf/shelf_icon_observer.h"
31 #include "ash/shelf/shelf_widget.h" 30 #include "ash/shelf/shelf_widget.h"
32 #include "base/auto_reset.h" 31 #include "base/auto_reset.h"
33 #include "base/metrics/histogram.h" 32 #include "base/metrics/histogram.h"
34 #include "grit/ash_strings.h" 33 #include "grit/ash_strings.h"
35 #include "ui/accessibility/ax_view_state.h" 34 #include "ui/accessibility/ax_view_state.h"
36 #include "ui/aura/window.h"
37 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/models/simple_menu_model.h" 36 #include "ui/base/models/simple_menu_model.h"
39 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/compositor/layer.h" 38 #include "ui/compositor/layer.h"
41 #include "ui/compositor/layer_animator.h" 39 #include "ui/compositor/layer_animator.h"
42 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 40 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
43 #include "ui/events/event_utils.h" 41 #include "ui/events/event_utils.h"
44 #include "ui/gfx/canvas.h" 42 #include "ui/gfx/canvas.h"
45 #include "ui/gfx/geometry/point.h" 43 #include "ui/gfx/geometry/point.h"
46 #include "ui/views/animation/bounds_animator.h" 44 #include "ui/views/animation/bounds_animator.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 350
353 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); 351 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
354 }; 352 };
355 353
356 // static 354 // static
357 const int ShelfView::kMinimumDragDistance = 8; 355 const int ShelfView::kMinimumDragDistance = 8;
358 356
359 ShelfView::ShelfView(ShelfModel* model, 357 ShelfView::ShelfView(ShelfModel* model,
360 ShelfDelegate* delegate, 358 ShelfDelegate* delegate,
361 WmShelf* wm_shelf, 359 WmShelf* wm_shelf,
362 Shelf* shelf) 360 ShelfWidget* shelf_widget)
363 : model_(model), 361 : model_(model),
364 delegate_(delegate), 362 delegate_(delegate),
365 wm_shelf_(wm_shelf), 363 wm_shelf_(wm_shelf),
366 shelf_(shelf), 364 shelf_widget_(shelf_widget),
367 view_model_(new views::ViewModel), 365 view_model_(new views::ViewModel),
368 first_visible_index_(0), 366 first_visible_index_(0),
369 last_visible_index_(-1), 367 last_visible_index_(-1),
370 overflow_button_(nullptr), 368 overflow_button_(nullptr),
371 owner_overflow_bubble_(nullptr), 369 owner_overflow_bubble_(nullptr),
372 tooltip_(this), 370 tooltip_(this),
373 drag_pointer_(NONE), 371 drag_pointer_(NONE),
374 drag_view_(nullptr), 372 drag_view_(nullptr),
375 start_drag_index_(-1), 373 start_drag_index_(-1),
376 context_menu_id_(0), 374 context_menu_id_(0),
377 leading_inset_(kDefaultLeadingInset), 375 leading_inset_(kDefaultLeadingInset),
378 cancelling_drag_model_changed_(false), 376 cancelling_drag_model_changed_(false),
379 last_hidden_index_(0), 377 last_hidden_index_(0),
380 closing_event_time_(base::TimeTicks()), 378 closing_event_time_(base::TimeTicks()),
381 drag_and_drop_item_pinned_(false), 379 drag_and_drop_item_pinned_(false),
382 drag_and_drop_shelf_id_(0), 380 drag_and_drop_shelf_id_(0),
383 drag_replaced_view_(nullptr), 381 drag_replaced_view_(nullptr),
384 dragged_off_shelf_(false), 382 dragged_off_shelf_(false),
385 snap_back_from_rip_off_view_(nullptr), 383 snap_back_from_rip_off_view_(nullptr),
386 overflow_mode_(false), 384 overflow_mode_(false),
387 main_shelf_(nullptr), 385 main_shelf_(nullptr),
388 dragged_off_from_overflow_to_shelf_(false), 386 dragged_off_from_overflow_to_shelf_(false),
389 is_repost_event_on_same_item_(false), 387 is_repost_event_on_same_item_(false),
390 last_pressed_index_(-1) { 388 last_pressed_index_(-1) {
391 DCHECK(model_); 389 DCHECK(model_);
392 DCHECK(delegate_); 390 DCHECK(delegate_);
393 DCHECK(wm_shelf_); 391 DCHECK(wm_shelf_);
392 DCHECK(shelf_widget_);
394 bounds_animator_.reset(new views::BoundsAnimator(this)); 393 bounds_animator_.reset(new views::BoundsAnimator(this));
395 bounds_animator_->AddObserver(this); 394 bounds_animator_->AddObserver(this);
396 set_context_menu_controller(this); 395 set_context_menu_controller(this);
397 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 396 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
398 } 397 }
399 398
400 ShelfView::~ShelfView() { 399 ShelfView::~ShelfView() {
401 bounds_animator_->RemoveObserver(this); 400 bounds_animator_->RemoveObserver(this);
402 model_->RemoveObserver(this); 401 model_->RemoveObserver(this);
403 } 402 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 470
472 void ShelfView::UpdatePanelIconPosition(ShelfID id, 471 void ShelfView::UpdatePanelIconPosition(ShelfID id,
473 const gfx::Point& midpoint) { 472 const gfx::Point& midpoint) {
474 int current_index = model_->ItemIndexByID(id); 473 int current_index = model_->ItemIndexByID(id);
475 int first_panel_index = model_->FirstPanelIndex(); 474 int first_panel_index = model_->FirstPanelIndex();
476 if (current_index < first_panel_index) 475 if (current_index < first_panel_index)
477 return; 476 return;
478 477
479 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), midpoint.y()); 478 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), midpoint.y());
480 int target_index = current_index; 479 int target_index = current_index;
481 while (target_index > first_panel_index && 480 while (
482 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(), 481 target_index > first_panel_index &&
482 wm_shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(),
483 view_model_->ideal_bounds(target_index).y()) > 483 view_model_->ideal_bounds(target_index).y()) >
484 shelf_->PrimaryAxisValue(midpoint_in_view.x(), 484 wm_shelf_->PrimaryAxisValue(midpoint_in_view.x(),
485 midpoint_in_view.y())) { 485 midpoint_in_view.y())) {
486 --target_index; 486 --target_index;
487 } 487 }
488 while (target_index < view_model_->view_size() - 1 && 488 while (target_index < view_model_->view_size() - 1 &&
489 shelf_->PrimaryAxisValue( 489 wm_shelf_->PrimaryAxisValue(
490 view_model_->ideal_bounds(target_index).right(), 490 view_model_->ideal_bounds(target_index).right(),
491 view_model_->ideal_bounds(target_index).bottom()) < 491 view_model_->ideal_bounds(target_index).bottom()) <
492 shelf_->PrimaryAxisValue(midpoint_in_view.x(), 492 wm_shelf_->PrimaryAxisValue(midpoint_in_view.x(),
493 midpoint_in_view.y())) { 493 midpoint_in_view.y())) {
494 ++target_index; 494 ++target_index;
495 } 495 }
496 if (current_index != target_index) 496 if (current_index != target_index)
497 model_->Move(current_index, target_index); 497 model_->Move(current_index, target_index);
498 } 498 }
499 499
500 bool ShelfView::IsShowingMenu() const { 500 bool ShelfView::IsShowingMenu() const {
501 return launcher_menu_runner_.get() && launcher_menu_runner_->IsRunning(); 501 return launcher_menu_runner_.get() && launcher_menu_runner_->IsRunning();
502 } 502 }
503 503
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 745
746 // Only when the repost event occurs on the same shelf item, we should ignore 746 // Only when the repost event occurs on the same shelf item, we should ignore
747 // the call in ShelfView::ButtonPressed(...). 747 // the call in ShelfView::ButtonPressed(...).
748 is_repost_event_on_same_item_ = 748 is_repost_event_on_same_item_ =
749 IsRepostEvent(event) && (last_pressed_index_ == index); 749 IsRepostEvent(event) && (last_pressed_index_ == index);
750 750
751 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 751 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
752 drag_view_ = static_cast<ShelfButton*>(view); 752 drag_view_ = static_cast<ShelfButton*>(view);
753 drag_origin_ = gfx::Point(event.x(), event.y()); 753 drag_origin_ = gfx::Point(event.x(), event.y());
754 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", 754 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage",
755 shelf_->SelectValueForShelfAlignment( 755 wm_shelf_->SelectValueForShelfAlignment(
756 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, 756 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
757 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, 757 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
758 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT), 758 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT),
759 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); 759 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
760 } 760 }
761 761
762 void ShelfView::PointerDraggedOnButton(views::View* view, 762 void ShelfView::PointerDraggedOnButton(views::View* view,
763 Pointer pointer, 763 Pointer pointer,
764 const ui::LocatedEvent& event) { 764 const ui::LocatedEvent& event) {
765 // To prepare all drag types (moving an item in the shelf and dragging off), 765 // To prepare all drag types (moving an item in the shelf and dragging off),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 // should be always true regardless of its position. 818 // should be always true regardless of its position.
819 if (dragged_off_from_overflow_to_shelf_ && 819 if (dragged_off_from_overflow_to_shelf_ &&
820 view_model_->view_at(i) == drag_view_) 820 view_model_->view_at(i) == drag_view_)
821 view_model_->view_at(i)->SetVisible(true); 821 view_model_->view_at(i)->SetVisible(true);
822 else 822 else
823 view_model_->view_at(i)->SetVisible(visible); 823 view_model_->view_at(i)->SetVisible(visible);
824 } 824 }
825 } 825 }
826 826
827 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) const { 827 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) const {
828 int available_size = shelf_->PrimaryAxisValue(width(), height()); 828 int available_size = wm_shelf_->PrimaryAxisValue(width(), height());
829 DCHECK(model_->item_count() == view_model_->view_size()); 829 DCHECK(model_->item_count() == view_model_->view_size());
830 if (!available_size) 830 if (!available_size)
831 return; 831 return;
832 832
833 int first_panel_index = model_->FirstPanelIndex(); 833 int first_panel_index = model_->FirstPanelIndex();
834 int last_button_index = first_panel_index - 1; 834 int last_button_index = first_panel_index - 1;
835 835
836 int x = 0; 836 int x = 0;
837 int y = 0; 837 int y = 0;
838 int button_size = GetShelfConstant(SHELF_BUTTON_SIZE); 838 int button_size = GetShelfConstant(SHELF_BUTTON_SIZE);
839 int button_spacing = GetShelfConstant(SHELF_BUTTON_SPACING); 839 int button_spacing = GetShelfConstant(SHELF_BUTTON_SPACING);
840 840
841 int w = shelf_->PrimaryAxisValue(button_size, width()); 841 int w = wm_shelf_->PrimaryAxisValue(button_size, width());
842 int h = shelf_->PrimaryAxisValue(height(), button_size); 842 int h = wm_shelf_->PrimaryAxisValue(height(), button_size);
843 for (int i = 0; i < view_model_->view_size(); ++i) { 843 for (int i = 0; i < view_model_->view_size(); ++i) {
844 if (i < first_visible_index_) { 844 if (i < first_visible_index_) {
845 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 845 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
846 continue; 846 continue;
847 } 847 }
848 848
849 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 849 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
850 x = shelf_->PrimaryAxisValue(x + w + button_spacing, x); 850 x = wm_shelf_->PrimaryAxisValue(x + w + button_spacing, x);
851 y = shelf_->PrimaryAxisValue(y, y + h + button_spacing); 851 y = wm_shelf_->PrimaryAxisValue(y, y + h + button_spacing);
852 } 852 }
853 853
854 if (is_overflow_mode()) { 854 if (is_overflow_mode()) {
855 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); 855 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode();
856 return; 856 return;
857 } 857 }
858 858
859 // Right aligned icons. 859 // Right aligned icons.
860 int end_position = available_size - button_spacing; 860 int end_position = available_size - button_spacing;
861 x = shelf_->PrimaryAxisValue(end_position, 0); 861 x = wm_shelf_->PrimaryAxisValue(end_position, 0);
862 y = shelf_->PrimaryAxisValue(0, end_position); 862 y = wm_shelf_->PrimaryAxisValue(0, end_position);
863 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { 863 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) {
864 x = shelf_->PrimaryAxisValue(x - w - button_spacing, x); 864 x = wm_shelf_->PrimaryAxisValue(x - w - button_spacing, x);
865 y = shelf_->PrimaryAxisValue(y, y - h - button_spacing); 865 y = wm_shelf_->PrimaryAxisValue(y, y - h - button_spacing);
866 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 866 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
867 end_position = shelf_->PrimaryAxisValue(x, y); 867 end_position = wm_shelf_->PrimaryAxisValue(x, y);
868 } 868 }
869 869
870 // Icons on the left / top are guaranteed up to kLeftIconProportion of 870 // Icons on the left / top are guaranteed up to kLeftIconProportion of
871 // the available space. 871 // the available space.
872 int last_icon_position = 872 int last_icon_position =
873 shelf_->PrimaryAxisValue( 873 wm_shelf_->PrimaryAxisValue(
874 view_model_->ideal_bounds(last_button_index).right(), 874 view_model_->ideal_bounds(last_button_index).right(),
875 view_model_->ideal_bounds(last_button_index).bottom()) + 875 view_model_->ideal_bounds(last_button_index).bottom()) +
876 button_size; 876 button_size;
877 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; 877 int reserved_icon_space = available_size * kReservedNonPanelIconProportion;
878 if (last_icon_position < reserved_icon_space) 878 if (last_icon_position < reserved_icon_space)
879 end_position = last_icon_position; 879 end_position = last_icon_position;
880 else 880 else
881 end_position = std::max(end_position, reserved_icon_space); 881 end_position = std::max(end_position, reserved_icon_space);
882 882
883 bounds->overflow_bounds.set_size( 883 bounds->overflow_bounds.set_size(
884 gfx::Size(shelf_->PrimaryAxisValue(w, width()), 884 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()),
885 shelf_->PrimaryAxisValue(height(), h))); 885 wm_shelf_->PrimaryAxisValue(height(), h)));
886 886
887 last_visible_index_ = DetermineLastVisibleIndex(end_position - button_size); 887 last_visible_index_ = DetermineLastVisibleIndex(end_position - button_size);
888 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; 888 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1;
889 bool show_overflow = last_visible_index_ < last_button_index || 889 bool show_overflow = last_visible_index_ < last_button_index ||
890 last_hidden_index_ >= first_panel_index; 890 last_hidden_index_ >= first_panel_index;
891 891
892 // Create Space for the overflow button 892 // Create Space for the overflow button
893 if (show_overflow) { 893 if (show_overflow) {
894 // The following code makes sure that platform apps icons (aligned to left / 894 // The following code makes sure that platform apps icons (aligned to left /
895 // top) are favored over panel apps icons (aligned to right / bottom). 895 // top) are favored over panel apps icons (aligned to right / bottom).
(...skipping 26 matching lines...) Expand all
922 view_model_->view_at(i)->SetVisible(visible); 922 view_model_->view_at(i)->SetVisible(visible);
923 } 923 }
924 924
925 overflow_button_->SetVisible(show_overflow); 925 overflow_button_->SetVisible(show_overflow);
926 if (show_overflow) { 926 if (show_overflow) {
927 DCHECK_NE(0, view_model_->view_size()); 927 DCHECK_NE(0, view_model_->view_size());
928 if (last_visible_index_ == -1) { 928 if (last_visible_index_ == -1) {
929 x = 0; 929 x = 0;
930 y = 0; 930 y = 0;
931 } else { 931 } else {
932 x = shelf_->PrimaryAxisValue( 932 x = wm_shelf_->PrimaryAxisValue(
933 view_model_->ideal_bounds(last_visible_index_).right(), 933 view_model_->ideal_bounds(last_visible_index_).right(),
934 view_model_->ideal_bounds(last_visible_index_).x()); 934 view_model_->ideal_bounds(last_visible_index_).x());
935 y = shelf_->PrimaryAxisValue( 935 y = wm_shelf_->PrimaryAxisValue(
936 view_model_->ideal_bounds(last_visible_index_).y(), 936 view_model_->ideal_bounds(last_visible_index_).y(),
937 view_model_->ideal_bounds(last_visible_index_).bottom()); 937 view_model_->ideal_bounds(last_visible_index_).bottom());
938 } 938 }
939 // Set all hidden panel icon positions to be on the overflow button. 939 // Set all hidden panel icon positions to be on the overflow button.
940 for (int i = first_panel_index; i <= last_hidden_index_; ++i) 940 for (int i = first_panel_index; i <= last_hidden_index_; ++i)
941 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 941 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
942 942
943 // Add more space between last visible item and overflow button. 943 // Add more space between last visible item and overflow button.
944 // Without this, two buttons look too close compared with other items. 944 // Without this, two buttons look too close compared with other items.
945 x = shelf_->PrimaryAxisValue(x + button_spacing, x); 945 x = wm_shelf_->PrimaryAxisValue(x + button_spacing, x);
946 y = shelf_->PrimaryAxisValue(y, y + button_spacing); 946 y = wm_shelf_->PrimaryAxisValue(y, y + button_spacing);
947 947
948 bounds->overflow_bounds.set_x(x); 948 bounds->overflow_bounds.set_x(x);
949 bounds->overflow_bounds.set_y(y); 949 bounds->overflow_bounds.set_y(y);
950 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) 950 if (overflow_bubble_.get() && overflow_bubble_->IsShowing())
951 UpdateOverflowRange(overflow_bubble_->shelf_view()); 951 UpdateOverflowRange(overflow_bubble_->shelf_view());
952 } else { 952 } else {
953 if (overflow_bubble_) 953 if (overflow_bubble_)
954 overflow_bubble_->Hide(); 954 overflow_bubble_->Hide();
955 } 955 }
956 } 956 }
957 957
958 int ShelfView::DetermineLastVisibleIndex(int max_value) const { 958 int ShelfView::DetermineLastVisibleIndex(int max_value) const {
959 int index = model_->FirstPanelIndex() - 1; 959 int index = model_->FirstPanelIndex() - 1;
960 while (index >= 0 && 960 while (index >= 0 &&
961 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).right(), 961 wm_shelf_->PrimaryAxisValue(
962 view_model_->ideal_bounds(index).bottom()) > 962 view_model_->ideal_bounds(index).right(),
963 max_value) { 963 view_model_->ideal_bounds(index).bottom()) > max_value) {
964 index--; 964 index--;
965 } 965 }
966 return index; 966 return index;
967 } 967 }
968 968
969 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const { 969 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const {
970 int index = model_->FirstPanelIndex(); 970 int index = model_->FirstPanelIndex();
971 while (index < view_model_->view_size() && 971 while (index < view_model_->view_size() &&
972 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).right(), 972 wm_shelf_->PrimaryAxisValue(
973 view_model_->ideal_bounds(index).bottom()) < 973 view_model_->ideal_bounds(index).right(),
974 min_value) { 974 view_model_->ideal_bounds(index).bottom()) < min_value) {
975 ++index; 975 ++index;
976 } 976 }
977 return index; 977 return index;
978 } 978 }
979 979
980 void ShelfView::AddIconObserver(ShelfIconObserver* observer) { 980 void ShelfView::AddIconObserver(ShelfIconObserver* observer) {
981 observers_.AddObserver(observer); 981 observers_.AddObserver(observer);
982 } 982 }
983 983
984 void ShelfView::RemoveIconObserver(ShelfIconObserver* observer) { 984 void ShelfView::RemoveIconObserver(ShelfIconObserver* observer) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 // Constrain the location to the range of valid indices for the type. 1095 // Constrain the location to the range of valid indices for the type.
1096 std::pair<int, int> indices(GetDragRange(current_index)); 1096 std::pair<int, int> indices(GetDragRange(current_index));
1097 int first_drag_index = indices.first; 1097 int first_drag_index = indices.first;
1098 int last_drag_index = indices.second; 1098 int last_drag_index = indices.second;
1099 // If the last index isn't valid, we're overflowing. Constrain to the app list 1099 // If the last index isn't valid, we're overflowing. Constrain to the app list
1100 // (which is the last visible item). 1100 // (which is the last visible item).
1101 if (first_drag_index < model_->FirstPanelIndex() && 1101 if (first_drag_index < model_->FirstPanelIndex() &&
1102 last_drag_index > last_visible_index_) 1102 last_drag_index > last_visible_index_)
1103 last_drag_index = last_visible_index_; 1103 last_drag_index = last_visible_index_;
1104 int x = 0, y = 0; 1104 int x = 0, y = 0;
1105 if (shelf_->IsHorizontalAlignment()) { 1105 if (wm_shelf_->IsHorizontalAlignment()) {
1106 x = std::max(view_model_->ideal_bounds(indices.first).x(), 1106 x = std::max(view_model_->ideal_bounds(indices.first).x(),
1107 drag_point.x() - drag_origin_.x()); 1107 drag_point.x() - drag_origin_.x());
1108 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - 1108 x = std::min(view_model_->ideal_bounds(last_drag_index).right() -
1109 view_model_->ideal_bounds(current_index).width(), 1109 view_model_->ideal_bounds(current_index).width(),
1110 x); 1110 x);
1111 if (drag_view_->x() == x) 1111 if (drag_view_->x() == x)
1112 return; 1112 return;
1113 drag_view_->SetX(x); 1113 drag_view_->SetX(x);
1114 } else { 1114 } else {
1115 y = std::max(view_model_->ideal_bounds(indices.first).y(), 1115 y = std::max(view_model_->ideal_bounds(indices.first).y(),
1116 drag_point.y() - drag_origin_.y()); 1116 drag_point.y() - drag_origin_.y());
1117 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() - 1117 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() -
1118 view_model_->ideal_bounds(current_index).height(), 1118 view_model_->ideal_bounds(current_index).height(),
1119 y); 1119 y);
1120 if (drag_view_->y() == y) 1120 if (drag_view_->y() == y)
1121 return; 1121 return;
1122 drag_view_->SetY(y); 1122 drag_view_->SetY(y);
1123 } 1123 }
1124 1124
1125 int target_index = views::ViewModelUtils::DetermineMoveIndex( 1125 int target_index = views::ViewModelUtils::DetermineMoveIndex(
1126 *view_model_, drag_view_, 1126 *view_model_, drag_view_,
1127 shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL 1127 wm_shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL
1128 : views::ViewModelUtils::VERTICAL, 1128 : views::ViewModelUtils::VERTICAL,
1129 x, y); 1129 x, y);
1130 target_index = 1130 target_index =
1131 std::min(indices.second, std::max(target_index, indices.first)); 1131 std::min(indices.second, std::max(target_index, indices.first));
1132 1132
1133 int first_draggable_item = 0; 1133 int first_draggable_item = 0;
1134 while (first_draggable_item < static_cast<int>(model_->items().size()) && 1134 while (first_draggable_item < static_cast<int>(model_->items().size()) &&
1135 !model_->GetShelfItemDelegate(model_->items()[first_draggable_item].id) 1135 !model_->GetShelfItemDelegate(model_->items()[first_draggable_item].id)
1136 ->IsDraggable()) { 1136 ->IsDraggable()) {
1137 first_draggable_item++; 1137 first_draggable_item++;
1138 } 1138 }
1139 1139
1140 target_index = std::max(target_index, first_draggable_item); 1140 target_index = std::max(target_index, first_draggable_item);
1141 1141
1142 if (target_index == current_index) 1142 if (target_index == current_index)
1143 return; 1143 return;
1144 1144
1145 // Change the model, the ShelfItemMoved() callback will handle the 1145 // Change the model, the ShelfItemMoved() callback will handle the
1146 // |view_model_| update. 1146 // |view_model_| update.
1147 model_->Move(current_index, target_index); 1147 model_->Move(current_index, target_index);
1148 bounds_animator_->StopAnimatingView(drag_view_); 1148 bounds_animator_->StopAnimatingView(drag_view_);
1149 } 1149 }
1150 1150
1151 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { 1151 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) {
1152 int current_index = view_model_->GetIndexOfView(drag_view_); 1152 int current_index = view_model_->GetIndexOfView(drag_view_);
1153 DCHECK_NE(-1, current_index); 1153 DCHECK_NE(-1, current_index);
1154 std::string dragged_app_id = 1154 std::string dragged_app_id =
1155 delegate_->GetAppIDForShelfID(model_->items()[current_index].id); 1155 delegate_->GetAppIDForShelfID(model_->items()[current_index].id);
1156 1156
1157 gfx::Point screen_location = event.root_location(); 1157 gfx::Point screen_location =
1158 ::wm::ConvertPointToScreen(GetWidget()->GetNativeWindow()->GetRootWindow(), 1158 WmLookup::Get()
1159 &screen_location); 1159 ->GetWindowForWidget(GetWidget())
1160 ->GetRootWindow()
1161 ->ConvertPointToScreen(event.root_location());
1160 1162
1161 // To avoid ugly forwards and backwards flipping we use different constants 1163 // To avoid ugly forwards and backwards flipping we use different constants
1162 // for ripping off / re-inserting the items. 1164 // for ripping off / re-inserting the items.
1163 if (dragged_off_shelf_) { 1165 if (dragged_off_shelf_) {
1164 // If the shelf/overflow bubble bounds contains |screen_location| we insert 1166 // If the shelf/overflow bubble bounds contains |screen_location| we insert
1165 // the item back into the shelf. 1167 // the item back into the shelf.
1166 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) { 1168 if (GetBoundsForDragInsertInScreen().Contains(screen_location)) {
1167 if (dragged_off_from_overflow_to_shelf_) { 1169 if (dragged_off_from_overflow_to_shelf_) {
1168 // During the dragging an item from Shelf to Overflow, it can enter here 1170 // During the dragging an item from Shelf to Overflow, it can enter here
1169 // directly because both are located very closly. 1171 // directly because both are located very closly.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 void ShelfView::ToggleOverflowBubble() { 1368 void ShelfView::ToggleOverflowBubble() {
1367 if (IsShowingOverflowBubble()) { 1369 if (IsShowingOverflowBubble()) {
1368 overflow_bubble_->Hide(); 1370 overflow_bubble_->Hide();
1369 return; 1371 return;
1370 } 1372 }
1371 1373
1372 if (!overflow_bubble_) 1374 if (!overflow_bubble_)
1373 overflow_bubble_.reset(new OverflowBubble(wm_shelf_)); 1375 overflow_bubble_.reset(new OverflowBubble(wm_shelf_));
1374 1376
1375 ShelfView* overflow_view = 1377 ShelfView* overflow_view =
1376 new ShelfView(model_, delegate_, wm_shelf_, shelf_); 1378 new ShelfView(model_, delegate_, wm_shelf_, shelf_widget_);
1377 overflow_view->overflow_mode_ = true; 1379 overflow_view->overflow_mode_ = true;
1378 overflow_view->Init(); 1380 overflow_view->Init();
1379 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); 1381 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
1380 overflow_view->OnShelfAlignmentChanged(); 1382 overflow_view->OnShelfAlignmentChanged();
1381 overflow_view->main_shelf_ = this; 1383 overflow_view->main_shelf_ = this;
1382 UpdateOverflowRange(overflow_view); 1384 UpdateOverflowRange(overflow_view);
1383 1385
1384 overflow_bubble_->Show(overflow_button_, overflow_view); 1386 overflow_bubble_->Show(overflow_button_, overflow_view);
1385 1387
1386 wm_shelf_->UpdateVisibilityState(); 1388 wm_shelf_->UpdateVisibilityState();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 const int last_button_index = view_model_->view_size() - 1; 1427 const int last_button_index = view_model_->view_size() - 1;
1426 gfx::Rect last_button_bounds = 1428 gfx::Rect last_button_bounds =
1427 view_model_->view_at(last_button_index)->bounds(); 1429 view_model_->view_at(last_button_index)->bounds();
1428 if (overflow_button_->visible() && 1430 if (overflow_button_->visible() &&
1429 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { 1431 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) {
1430 // When overflow button is visible and shelf has no panel items, 1432 // When overflow button is visible and shelf has no panel items,
1431 // last_button_bounds should be overflow button's bounds. 1433 // last_button_bounds should be overflow button's bounds.
1432 last_button_bounds = overflow_button_->bounds(); 1434 last_button_bounds = overflow_button_->bounds();
1433 } 1435 }
1434 1436
1435 if (shelf_->IsHorizontalAlignment()) { 1437 if (wm_shelf_->IsHorizontalAlignment()) {
1436 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_, 1438 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_,
1437 GetShelfConstant(SHELF_SIZE)); 1439 GetShelfConstant(SHELF_SIZE));
1438 } else { 1440 } else {
1439 preferred_size = gfx::Size(GetShelfConstant(SHELF_SIZE), 1441 preferred_size = gfx::Size(GetShelfConstant(SHELF_SIZE),
1440 last_button_bounds.bottom() + leading_inset_); 1442 last_button_bounds.bottom() + leading_inset_);
1441 } 1443 }
1442 } 1444 }
1443 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); 1445 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0);
1444 1446
1445 // In overflow mode, we should use OverflowBubbleView as a source for 1447 // In overflow mode, we should use OverflowBubbleView as a source for
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 if (is_overflow_mode() && dragged_off_shelf_ && 1501 if (is_overflow_mode() && dragged_off_shelf_ &&
1500 !dragged_off_from_overflow_to_shelf_ && 1502 !dragged_off_from_overflow_to_shelf_ &&
1501 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) 1503 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
1502 last_button_index--; 1504 last_button_index--;
1503 1505
1504 const gfx::Rect last_button_bounds = 1506 const gfx::Rect last_button_bounds =
1505 last_button_index >= first_visible_index_ 1507 last_button_index >= first_visible_index_
1506 ? view_model_->ideal_bounds(last_button_index) 1508 ? view_model_->ideal_bounds(last_button_index)
1507 : gfx::Rect(gfx::Size(shelf_size, shelf_size)); 1509 : gfx::Rect(gfx::Size(shelf_size, shelf_size));
1508 1510
1509 if (shelf_->IsHorizontalAlignment()) 1511 if (wm_shelf_->IsHorizontalAlignment())
1510 return gfx::Size(last_button_bounds.right() + leading_inset_, shelf_size); 1512 return gfx::Size(last_button_bounds.right() + leading_inset_, shelf_size);
1511 1513
1512 return gfx::Size(shelf_size, last_button_bounds.bottom() + leading_inset_); 1514 return gfx::Size(shelf_size, last_button_bounds.bottom() + leading_inset_);
1513 } 1515 }
1514 1516
1515 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 1517 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
1516 // This bounds change is produced by the shelf movement and all content has 1518 // This bounds change is produced by the shelf movement and all content has
1517 // to follow. Using an animation at that time would produce a time lag since 1519 // to follow. Using an animation at that time would produce a time lag since
1518 // the animation of the BoundsAnimator has itself a delay before it arrives 1520 // the animation of the BoundsAnimator has itself a delay before it arrives
1519 // at the required location. As such we tell the animator to go there 1521 // at the required location. As such we tell the animator to go there
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 // It is possible to invoke the menu while it is sliding into view. To cover 1832 // It is possible to invoke the menu while it is sliding into view. To cover
1831 // that case, the screen coordinates are offsetted by the animation delta. 1833 // that case, the screen coordinates are offsetted by the animation delta.
1832 anchor = source->GetBoundsInScreen() + (window->GetTargetBounds().origin() - 1834 anchor = source->GetBoundsInScreen() + (window->GetTargetBounds().origin() -
1833 window->GetBounds().origin()); 1835 window->GetBounds().origin());
1834 1836
1835 // Adjust the anchor location for shelf items with asymmetrical borders. 1837 // Adjust the anchor location for shelf items with asymmetrical borders.
1836 if (source->border()) 1838 if (source->border())
1837 anchor.Inset(source->border()->GetInsets()); 1839 anchor.Inset(source->border()->GetInsets());
1838 1840
1839 // Determine the menu alignment dependent on the shelf. 1841 // Determine the menu alignment dependent on the shelf.
1840 menu_alignment = shelf_->SelectValueForShelfAlignment( 1842 switch (wm_shelf_->GetAlignment()) {
1841 views::MENU_ANCHOR_BUBBLE_ABOVE, views::MENU_ANCHOR_BUBBLE_RIGHT, 1843 case SHELF_ALIGNMENT_BOTTOM:
1842 views::MENU_ANCHOR_BUBBLE_LEFT); 1844 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1845 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE;
1846 break;
1847 case SHELF_ALIGNMENT_LEFT:
1848 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT;
1849 break;
1850 case SHELF_ALIGNMENT_RIGHT:
1851 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT;
1852 break;
1853 }
1843 } 1854 }
1844 1855
1845 shelf_->shelf_widget()->ForceUndimming(true); 1856 shelf_widget_->ForceUndimming(true);
1846 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. 1857 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code.
1847 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, 1858 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor,
1848 menu_alignment, source_type); 1859 menu_alignment, source_type);
1849 } 1860 }
1850 1861
1851 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { 1862 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) {
1852 context_menu_id_ = 0; 1863 context_menu_id_ = 0;
1853 shelf_->shelf_widget()->ForceUndimming(false); 1864 shelf_widget_->ForceUndimming(false);
1854 1865
1855 // Hide the hide overflow bubble after showing a context menu for its items. 1866 // Hide the hide overflow bubble after showing a context menu for its items.
1856 if (owner_overflow_bubble_) 1867 if (owner_overflow_bubble_)
1857 owner_overflow_bubble_->HideBubbleAndRefreshButton(); 1868 owner_overflow_bubble_->HideBubbleAndRefreshButton();
1858 1869
1859 closing_event_time_ = launcher_menu_runner_->closing_event_time(); 1870 closing_event_time_ = launcher_menu_runner_->closing_event_time();
1860 1871
1861 if (ink_drop) 1872 if (ink_drop)
1862 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); 1873 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED);
1863 1874
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 return closing_event_time_ == event.time_stamp(); 1917 return closing_event_time_ == event.time_stamp();
1907 } 1918 }
1908 1919
1909 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { 1920 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
1910 const int view_index = view_model_->GetIndexOfView(view); 1921 const int view_index = view_model_->GetIndexOfView(view);
1911 return (view_index < 0) ? nullptr : &(model_->items()[view_index]); 1922 return (view_index < 0) ? nullptr : &(model_->items()[view_index]);
1912 } 1923 }
1913 1924
1914 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1925 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1915 const gfx::Rect bounds = GetBoundsInScreen(); 1926 const gfx::Rect bounds = GetBoundsInScreen();
1916 int distance = shelf_->SelectValueForShelfAlignment( 1927 int distance = wm_shelf_->SelectValueForShelfAlignment(
1917 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1928 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1918 bounds.x() - coordinate.x()); 1929 bounds.x() - coordinate.x());
1919 return distance > 0 ? distance : 0; 1930 return distance > 0 ? distance : 0;
1920 } 1931 }
1921 1932
1922 } // namespace ash 1933 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_view.h ('k') | ash/common/shelf/wm_shelf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698