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

Side by Side Diff: ash/shelf/shelf_layout_manager.cc

Issue 1998933002: Update shelf spacing in Chrome OS according to the MD specs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/accelerators/accelerator_commands.h" 13 #include "ash/accelerators/accelerator_commands.h"
14 #include "ash/ash_switches.h" 14 #include "ash/ash_switches.h"
15 #include "ash/material_design/material_design_controller.h"
15 #include "ash/root_window_controller.h" 16 #include "ash/root_window_controller.h"
16 #include "ash/screen_util.h" 17 #include "ash/screen_util.h"
17 #include "ash/session/session_state_delegate.h" 18 #include "ash/session/session_state_delegate.h"
18 #include "ash/shelf/shelf.h" 19 #include "ash/shelf/shelf.h"
19 #include "ash/shelf/shelf_bezel_event_filter.h" 20 #include "ash/shelf/shelf_bezel_event_filter.h"
20 #include "ash/shelf/shelf_constants.h" 21 #include "ash/shelf/shelf_constants.h"
21 #include "ash/shelf/shelf_layout_manager_observer.h" 22 #include "ash/shelf/shelf_layout_manager_observer.h"
22 #include "ash/shelf/shelf_util.h" 23 #include "ash/shelf/shelf_util.h"
23 #include "ash/shelf/shelf_widget.h" 24 #include "ash/shelf/shelf_widget.h"
24 #include "ash/shell.h" 25 #include "ash/shell.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // auto hidden shelf. The region is used to make it easier to trigger showing 80 // auto hidden shelf. The region is used to make it easier to trigger showing
80 // the auto hidden shelf when the shelf is on the boundary between displays. 81 // the auto hidden shelf when the shelf is on the boundary between displays.
81 const int kMaxAutoHideShowShelfRegionSize = 10; 82 const int kMaxAutoHideShowShelfRegionSize = 10;
82 83
83 ui::Layer* GetLayer(views::Widget* widget) { 84 ui::Layer* GetLayer(views::Widget* widget) {
84 return widget->GetNativeView()->layer(); 85 return widget->GetNativeView()->layer();
85 } 86 }
86 87
87 } // namespace 88 } // namespace
88 89
89 // static
90 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2;
91
92 // static
93 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5;
94
95 // static
96 const int ShelfLayoutManager::kAutoHideSize = 3;
97
98 // static
99 const int ShelfLayoutManager::kShelfItemInset = 3;
100
101 // ShelfLayoutManager::AutoHideEventFilter ------------------------------------- 90 // ShelfLayoutManager::AutoHideEventFilter -------------------------------------
102 91
103 // Notifies ShelfLayoutManager any time the mouse moves. 92 // Notifies ShelfLayoutManager any time the mouse moves.
104 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler { 93 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler {
105 public: 94 public:
106 explicit AutoHideEventFilter(ShelfLayoutManager* shelf); 95 explicit AutoHideEventFilter(ShelfLayoutManager* shelf);
107 ~AutoHideEventFilter() override; 96 ~AutoHideEventFilter() override;
108 97
109 // Returns true if the last mouse event was a mouse drag. 98 // Returns true if the last mouse event was a mouse drag.
110 bool in_mouse_drag() const { return in_mouse_drag_; } 99 bool in_mouse_drag() const { return in_mouse_drag_; }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 return shelf_->status_area_widget() && 265 return shelf_->status_area_widget() &&
277 shelf_->status_area_widget()->IsVisible() && 266 shelf_->status_area_widget()->IsVisible() &&
278 (state_.visibility_state == SHELF_VISIBLE || 267 (state_.visibility_state == SHELF_VISIBLE ||
279 (state_.visibility_state == SHELF_AUTO_HIDE && 268 (state_.visibility_state == SHELF_AUTO_HIDE &&
280 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); 269 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN));
281 } 270 }
282 271
283 gfx::Rect ShelfLayoutManager::GetIdealBounds() { 272 gfx::Rect ShelfLayoutManager::GetIdealBounds() {
284 gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView())); 273 gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView()));
285 return SelectValueForShelfAlignment( 274 return SelectValueForShelfAlignment(
286 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), 275 gfx::Rect(rect.x(), rect.bottom() - GetShelfLayoutConstant(SHELF_SIZE),
287 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), 276 rect.width(), GetShelfLayoutConstant(SHELF_SIZE)),
288 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, 277 gfx::Rect(rect.x(), rect.y(), GetShelfLayoutConstant(SHELF_SIZE),
289 rect.height())); 278 rect.height()),
279 gfx::Rect(rect.right() - GetShelfLayoutConstant(SHELF_SIZE), rect.y(),
280 GetShelfLayoutConstant(SHELF_SIZE), rect.height()));
290 } 281 }
291 282
292 void ShelfLayoutManager::LayoutShelf() { 283 void ShelfLayoutManager::LayoutShelf() {
293 TargetBounds target_bounds; 284 TargetBounds target_bounds;
294 CalculateTargetBounds(state_, &target_bounds); 285 CalculateTargetBounds(state_, &target_bounds);
295 UpdateBoundsAndOpacity(target_bounds, false, NULL); 286 UpdateBoundsAndOpacity(target_bounds, false, NULL);
296 287
297 // Update insets in ShelfWindowTargeter when shelf bounds change. 288 // Update insets in ShelfWindowTargeter when shelf bounds change.
298 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 289 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
299 WillChangeVisibilityState(visibility_state())); 290 WillChangeVisibilityState(visibility_state()));
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 530
540 bool ShelfLayoutManager::IsHorizontalAlignment() const { 531 bool ShelfLayoutManager::IsHorizontalAlignment() const {
541 return wm::IsHorizontalAlignment(GetAlignment()); 532 return wm::IsHorizontalAlignment(GetAlignment());
542 } 533 }
543 534
544 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { 535 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) {
545 chromevox_panel_height_ = height; 536 chromevox_panel_height_ = height;
546 LayoutShelf(); 537 LayoutShelf();
547 } 538 }
548 539
540 // static
541 int ShelfLayoutManager::GetShelfItemInset(
542 ShelfLayoutManager::ShelfItemInset constant) {
543 const int kShelfItemInset[] = {3, 4};
544
545 int mode = MaterialDesignController::Mode::NON_MATERIAL;
546 if (MaterialDesignController::IsShelfMaterial())
547 mode = MaterialDesignController::Mode::MATERIAL_NORMAL;
548
549 switch (constant) {
550 case ShelfLayoutManager::ShelfItemInset::SHELF_ITEM_INSET:
551 return kShelfItemInset[mode];
552 }
553 NOTREACHED();
554 return 0;
555 }
556
549 //////////////////////////////////////////////////////////////////////////////// 557 ////////////////////////////////////////////////////////////////////////////////
550 // ShelfLayoutManager, private: 558 // ShelfLayoutManager, private:
551 559
552 ShelfLayoutManager::TargetBounds::TargetBounds() 560 ShelfLayoutManager::TargetBounds::TargetBounds()
553 : opacity(0.0f), status_opacity(0.0f) {} 561 : opacity(0.0f), status_opacity(0.0f) {}
554 562
555 ShelfLayoutManager::TargetBounds::~TargetBounds() {} 563 ShelfLayoutManager::TargetBounds::~TargetBounds() {}
556 564
557 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { 565 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
558 if (!shelf_->GetNativeView()) 566 if (!shelf_->GetNativeView())
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 shelf_->status_area_widget()->Show(); 738 shelf_->status_area_widget()->Show();
731 } 739 }
732 740
733 void ShelfLayoutManager::StopAnimating() { 741 void ShelfLayoutManager::StopAnimating() {
734 GetLayer(shelf_)->GetAnimator()->StopAnimating(); 742 GetLayer(shelf_)->GetAnimator()->StopAnimating();
735 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); 743 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating();
736 } 744 }
737 745
738 void ShelfLayoutManager::CalculateTargetBounds(const State& state, 746 void ShelfLayoutManager::CalculateTargetBounds(const State& state,
739 TargetBounds* target_bounds) { 747 TargetBounds* target_bounds) {
740 int shelf_size = kShelfSize; 748 int shelf_size = GetShelfLayoutConstant(SHELF_SIZE);
741 if (state.visibility_state == SHELF_AUTO_HIDE && 749 if (state.visibility_state == SHELF_AUTO_HIDE &&
742 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { 750 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
743 // Auto-hidden shelf always starts with the default size. If a gesture-drag 751 // Auto-hidden shelf always starts with the default size. If a gesture-drag
744 // is in progress, then the call to UpdateTargetBoundsForGesture() below 752 // is in progress, then the call to UpdateTargetBoundsForGesture() below
745 // takes care of setting the height properly. 753 // takes care of setting the height properly.
746 shelf_size = kAutoHideSize; 754 shelf_size = kAutoHideSize;
747 } else if (state.visibility_state == SHELF_HIDDEN || 755 } else if (state.visibility_state == SHELF_HIDDEN ||
748 (!keyboard_bounds_.IsEmpty() && 756 (!keyboard_bounds_.IsEmpty() &&
749 !keyboard::IsKeyboardOverscrollEnabled())) { 757 !keyboard::IsKeyboardOverscrollEnabled())) {
750 shelf_size = 0; 758 shelf_size = 0;
(...skipping 12 matching lines...) Expand all
763 gfx::Point shelf_origin = SelectValueForShelfAlignment( 771 gfx::Point shelf_origin = SelectValueForShelfAlignment(
764 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), 772 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset),
765 gfx::Point(available_bounds.x(), available_bounds.y()), 773 gfx::Point(available_bounds.x(), available_bounds.y()),
766 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); 774 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y()));
767 target_bounds->shelf_bounds_in_root = 775 target_bounds->shelf_bounds_in_root =
768 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); 776 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height);
769 777
770 gfx::Size status_size( 778 gfx::Size status_size(
771 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); 779 shelf_->status_area_widget()->GetWindowBoundsInScreen().size());
772 if (IsHorizontalAlignment()) 780 if (IsHorizontalAlignment())
773 status_size.set_height(kShelfSize); 781 status_size.set_height(GetShelfLayoutConstant(SHELF_SIZE));
774 else 782 else
775 status_size.set_width(kShelfSize); 783 status_size.set_width(GetShelfLayoutConstant(SHELF_SIZE));
776 784
777 gfx::Point status_origin = SelectValueForShelfAlignment( 785 gfx::Point status_origin = SelectValueForShelfAlignment(
778 gfx::Point(0, 0), 786 gfx::Point(0, 0),
779 gfx::Point(shelf_width - status_size.width(), 787 gfx::Point(shelf_width - status_size.width(),
780 shelf_height - status_size.height()), 788 shelf_height - status_size.height()),
781 gfx::Point(0, shelf_height - status_size.height())); 789 gfx::Point(0, shelf_height - status_size.height()));
782 if (IsHorizontalAlignment() && !base::i18n::IsRTL()) 790 if (IsHorizontalAlignment() && !base::i18n::IsRTL())
783 status_origin.set_x(shelf_width - status_size.width()); 791 status_origin.set_x(shelf_width - status_size.width());
784 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); 792 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size);
785 793
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); 857 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_);
850 int resistance_free_region = 0; 858 int resistance_free_region = 0;
851 859
852 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && 860 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
853 visibility_state() == SHELF_AUTO_HIDE && 861 visibility_state() == SHELF_AUTO_HIDE &&
854 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { 862 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) {
855 // If the shelf was hidden when the drag started (and the state hasn't 863 // If the shelf was hidden when the drag started (and the state hasn't
856 // changed since then, e.g. because the tray-menu was shown because of the 864 // changed since then, e.g. because the tray-menu was shown because of the
857 // drag), then allow the drag some resistance-free region at first to make 865 // drag), then allow the drag some resistance-free region at first to make
858 // sure the shelf sticks with the finger until the shelf is visible. 866 // sure the shelf sticks with the finger until the shelf is visible.
859 resistance_free_region = kShelfSize - kAutoHideSize; 867 resistance_free_region = GetShelfLayoutConstant(SHELF_SIZE) - kAutoHideSize;
860 } 868 }
861 869
862 bool resist = SelectValueForShelfAlignment( 870 bool resist = SelectValueForShelfAlignment(
863 gesture_drag_amount_ < -resistance_free_region, 871 gesture_drag_amount_ < -resistance_free_region,
864 gesture_drag_amount_ > resistance_free_region, 872 gesture_drag_amount_ > resistance_free_region,
865 gesture_drag_amount_ < -resistance_free_region); 873 gesture_drag_amount_ < -resistance_free_region);
866 874
867 float translate = 0.f; 875 float translate = 0.f;
868 if (resist) { 876 if (resist) {
869 float diff = fabsf(gesture_drag_amount_) - resistance_free_region; 877 float diff = fabsf(gesture_drag_amount_) - resistance_free_region;
(...skipping 30 matching lines...) Expand all
900 if (right_aligned) { 908 if (right_aligned) {
901 target_bounds->shelf_bounds_in_root.set_x( 909 target_bounds->shelf_bounds_in_root.set_x(
902 available_bounds.right() - shelf_width); 910 available_bounds.right() - shelf_width);
903 } 911 }
904 912
905 if (right_aligned) 913 if (right_aligned)
906 target_bounds->status_bounds_in_shelf.set_x(0); 914 target_bounds->status_bounds_in_shelf.set_x(0);
907 else 915 else
908 target_bounds->status_bounds_in_shelf.set_x( 916 target_bounds->status_bounds_in_shelf.set_x(
909 target_bounds->shelf_bounds_in_root.width() - 917 target_bounds->shelf_bounds_in_root.width() -
910 kShelfSize); 918 GetShelfLayoutConstant(SHELF_SIZE));
911 } 919 }
912 } 920 }
913 921
914 void ShelfLayoutManager::UpdateShelfBackground( 922 void ShelfLayoutManager::UpdateShelfBackground(
915 BackgroundAnimatorChangeType type) { 923 BackgroundAnimatorChangeType type) {
916 const wm::ShelfBackgroundType background_type(GetShelfBackgroundType()); 924 const wm::ShelfBackgroundType background_type(GetShelfBackgroundType());
917 shelf_->SetPaintsBackground(background_type, type); 925 shelf_->SetPaintsBackground(background_type, type);
918 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 926 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
919 OnBackgroundUpdated(background_type, type)); 927 OnBackgroundUpdated(background_type, type));
920 } 928 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 UpdateBoundsAndOpacity(target_bounds, true, NULL); 1153 UpdateBoundsAndOpacity(target_bounds, true, NULL);
1146 UpdateVisibilityState(); 1154 UpdateVisibilityState();
1147 } 1155 }
1148 1156
1149 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { 1157 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() {
1150 UpdateVisibilityState(); 1158 UpdateVisibilityState();
1151 LayoutShelf(); 1159 LayoutShelf();
1152 } 1160 }
1153 1161
1154 } // namespace ash 1162 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698