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/common/system/status_area_widget_delegate.h" | 5 #include "ash/common/system/status_area_widget_delegate.h" |
6 | 6 |
7 #include "ash/ash_export.h" | 7 #include "ash/ash_export.h" |
8 #include "ash/common/focus_cycler.h" | 8 #include "ash/common/focus_cycler.h" |
9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/gfx/animation/tween.h" | 22 #include "ui/gfx/animation/tween.h" |
23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
25 #include "ui/views/accessible_pane_view.h" | 25 #include "ui/views/accessible_pane_view.h" |
26 #include "ui/views/border.h" | 26 #include "ui/views/border.h" |
27 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 const int kAnimationDurationMs = 250; | 32 constexpr int kAnimationDurationMs = 250; |
| 33 |
| 34 constexpr int kPaddingFromEdgeOfShelf = 3; |
33 | 35 |
34 class StatusAreaWidgetDelegateAnimationSettings | 36 class StatusAreaWidgetDelegateAnimationSettings |
35 : public ui::ScopedLayerAnimationSettings { | 37 : public ui::ScopedLayerAnimationSettings { |
36 public: | 38 public: |
37 explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer) | 39 explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer) |
38 : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) { | 40 : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) { |
39 SetTransitionDuration( | 41 SetTransitionDuration( |
40 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); | 42 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
41 SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 43 SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
42 SetTweenType(gfx::Tween::EASE_IN_OUT); | 44 SetTweenType(gfx::Tween::EASE_IN_OUT); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 175 } |
174 | 176 |
175 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 177 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
176 if (GetWidget()) | 178 if (GetWidget()) |
177 GetWidget()->SetSize(GetPreferredSize()); | 179 GetWidget()->SetSize(GetPreferredSize()); |
178 } | 180 } |
179 | 181 |
180 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, | 182 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, |
181 bool extend_border_to_edge) { | 183 bool extend_border_to_edge) { |
182 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 184 const int shelf_size = GetShelfConstant(SHELF_SIZE); |
183 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); | 185 const int item_height = kTrayItemSize; |
184 int top_edge, left_edge, bottom_edge, right_edge; | 186 int top_edge, left_edge, bottom_edge, right_edge; |
185 | 187 |
186 // Tray views are laid out right-to-left or bottom-to-top. | 188 // Tray views are laid out right-to-left or bottom-to-top. |
187 if (MaterialDesignController::IsShelfMaterial()) { | 189 if (MaterialDesignController::IsShelfMaterial()) { |
188 const bool horizontal_alignment = IsHorizontalAlignment(alignment_); | 190 const bool horizontal_alignment = IsHorizontalAlignment(alignment_); |
189 const int padding = (shelf_size - item_height) / 2; | 191 const int padding = (shelf_size - item_height) / 2; |
190 const int extended_padding = | 192 const int extended_padding = kPaddingFromEdgeOfShelf; |
191 GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF); | |
192 | 193 |
193 top_edge = horizontal_alignment ? padding : 0; | 194 top_edge = horizontal_alignment ? padding : 0; |
194 left_edge = horizontal_alignment ? 0 : padding; | 195 left_edge = horizontal_alignment ? 0 : padding; |
195 bottom_edge = horizontal_alignment | 196 bottom_edge = horizontal_alignment |
196 ? padding | 197 ? padding |
197 : (extend_border_to_edge ? extended_padding : 0); | 198 : (extend_border_to_edge ? extended_padding : 0); |
198 right_edge = horizontal_alignment | 199 right_edge = horizontal_alignment |
199 ? (extend_border_to_edge ? extended_padding : 0) | 200 ? (extend_border_to_edge ? extended_padding : 0) |
200 : padding; | 201 : padding; |
201 } else { | 202 } else { |
202 bool on_edge = (child == child_at(0)); | 203 bool on_edge = (child == child_at(0)); |
203 if (IsHorizontalAlignment(alignment_)) { | 204 if (IsHorizontalAlignment(alignment_)) { |
204 top_edge = kShelfItemInset; | 205 top_edge = kShelfItemInset; |
205 left_edge = 0; | 206 left_edge = 0; |
206 bottom_edge = shelf_size - kShelfItemInset - item_height; | 207 bottom_edge = shelf_size - kShelfItemInset - item_height; |
207 right_edge = | 208 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
208 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
209 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { | 209 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { |
210 top_edge = 0; | 210 top_edge = 0; |
211 left_edge = shelf_size - kShelfItemInset - item_height; | 211 left_edge = shelf_size - kShelfItemInset - item_height; |
212 bottom_edge = | 212 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
213 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
214 right_edge = kShelfItemInset; | 213 right_edge = kShelfItemInset; |
215 } else { // SHELF_ALIGNMENT_RIGHT | 214 } else { // SHELF_ALIGNMENT_RIGHT |
216 top_edge = 0; | 215 top_edge = 0; |
217 left_edge = kShelfItemInset; | 216 left_edge = kShelfItemInset; |
218 bottom_edge = | 217 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
219 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
220 right_edge = shelf_size - kShelfItemInset - item_height; | 218 right_edge = shelf_size - kShelfItemInset - item_height; |
221 } | 219 } |
222 } | 220 } |
223 child->SetBorder( | 221 child->SetBorder( |
224 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); | 222 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); |
225 // Layout on |child| needs to be updated based on new border value before | 223 // Layout on |child| needs to be updated based on new border value before |
226 // displaying; otherwise |child| will be showing with old border size. | 224 // displaying; otherwise |child| will be showing with old border size. |
227 // Fix for crbug.com/623438. | 225 // Fix for crbug.com/623438. |
228 child->Layout(); | 226 child->Layout(); |
229 } | 227 } |
230 | 228 |
231 } // namespace ash | 229 } // namespace ash |
OLD | NEW |