| 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" | |
| 8 #include "ash/common/focus_cycler.h" | 7 #include "ash/common/focus_cycler.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | |
| 10 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
| 13 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 14 #include "ash/common/wm_lookup.h" | 12 #include "ash/common/wm_lookup.h" |
| 15 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 16 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 17 #include "ash/public/cpp/shell_window_ids.h" | |
| 18 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 19 #include "base/strings/utf_string_conversions.h" | |
| 20 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
| 21 #include "ui/compositor/scoped_layer_animation_settings.h" | 17 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 22 #include "ui/gfx/animation/tween.h" | 18 #include "ui/gfx/animation/tween.h" |
| 23 #include "ui/gfx/canvas.h" | |
| 24 #include "ui/gfx/image/image.h" | |
| 25 #include "ui/views/accessible_pane_view.h" | 19 #include "ui/views/accessible_pane_view.h" |
| 26 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
| 27 #include "ui/views/layout/grid_layout.h" | 21 #include "ui/views/layout/grid_layout.h" |
| 28 #include "ui/views/widget/widget.h" | |
| 29 | 22 |
| 30 namespace { | 23 namespace { |
| 31 | 24 |
| 32 const int kAnimationDurationMs = 250; | 25 const int kAnimationDurationMs = 250; |
| 33 | 26 |
| 34 class StatusAreaWidgetDelegateAnimationSettings | 27 class StatusAreaWidgetDelegateAnimationSettings |
| 35 : public ui::ScopedLayerAnimationSettings { | 28 : public ui::ScopedLayerAnimationSettings { |
| 36 public: | 29 public: |
| 37 explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer) | 30 explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer) |
| 38 : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) { | 31 : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 UpdateLayout(); | 165 UpdateLayout(); |
| 173 } | 166 } |
| 174 | 167 |
| 175 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 168 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
| 176 if (GetWidget()) | 169 if (GetWidget()) |
| 177 GetWidget()->SetSize(GetPreferredSize()); | 170 GetWidget()->SetSize(GetPreferredSize()); |
| 178 } | 171 } |
| 179 | 172 |
| 180 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, | 173 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, |
| 181 bool extend_border_to_edge) { | 174 bool extend_border_to_edge) { |
| 182 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 175 // Tray views are laid out right-to-left or bottom-to-top. |
| 183 const int item_height = GetTrayConstant(TRAY_ITEM_HEIGHT_LEGACY); | 176 const bool horizontal_alignment = IsHorizontalAlignment(alignment_); |
| 184 int top_edge, left_edge, bottom_edge, right_edge; | 177 const int padding = (GetShelfConstant(SHELF_SIZE) - kTrayItemSize) / 2; |
| 185 | 178 |
| 186 // Tray views are laid out right-to-left or bottom-to-top. | 179 const int top_edge = horizontal_alignment ? padding : 0; |
| 187 if (MaterialDesignController::IsShelfMaterial()) { | 180 const int left_edge = horizontal_alignment ? 0 : padding; |
| 188 const bool horizontal_alignment = IsHorizontalAlignment(alignment_); | 181 const int bottom_edge = |
| 189 const int padding = (shelf_size - item_height) / 2; | 182 horizontal_alignment |
| 190 const int extended_padding = | 183 ? padding |
| 191 GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF); | 184 : (extend_border_to_edge ? kTrayPaddingFromEdgeOfShelf : 0); |
| 192 | 185 const int right_edge = |
| 193 top_edge = horizontal_alignment ? padding : 0; | 186 horizontal_alignment |
| 194 left_edge = horizontal_alignment ? 0 : padding; | 187 ? (extend_border_to_edge ? kTrayPaddingFromEdgeOfShelf : 0) |
| 195 bottom_edge = horizontal_alignment | 188 : padding; |
| 196 ? padding | |
| 197 : (extend_border_to_edge ? extended_padding : 0); | |
| 198 right_edge = horizontal_alignment | |
| 199 ? (extend_border_to_edge ? extended_padding : 0) | |
| 200 : padding; | |
| 201 } else { | |
| 202 bool on_edge = (child == child_at(0)); | |
| 203 if (IsHorizontalAlignment(alignment_)) { | |
| 204 top_edge = kShelfItemInset; | |
| 205 left_edge = 0; | |
| 206 bottom_edge = shelf_size - kShelfItemInset - item_height; | |
| 207 right_edge = | |
| 208 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 209 } else if (alignment_ == SHELF_ALIGNMENT_LEFT) { | |
| 210 top_edge = 0; | |
| 211 left_edge = shelf_size - kShelfItemInset - item_height; | |
| 212 bottom_edge = | |
| 213 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 214 right_edge = kShelfItemInset; | |
| 215 } else { // SHELF_ALIGNMENT_RIGHT | |
| 216 top_edge = 0; | |
| 217 left_edge = kShelfItemInset; | |
| 218 bottom_edge = | |
| 219 on_edge ? GetTrayConstant(TRAY_PADDING_FROM_EDGE_OF_SHELF) : 0; | |
| 220 right_edge = shelf_size - kShelfItemInset - item_height; | |
| 221 } | |
| 222 } | |
| 223 child->SetBorder( | 189 child->SetBorder( |
| 224 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); | 190 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); |
| 191 |
| 225 // Layout on |child| needs to be updated based on new border value before | 192 // Layout on |child| needs to be updated based on new border value before |
| 226 // displaying; otherwise |child| will be showing with old border size. | 193 // displaying; otherwise |child| will be showing with old border size. |
| 227 // Fix for crbug.com/623438. | 194 // Fix for crbug.com/623438. |
| 228 child->Layout(); | 195 child->Layout(); |
| 229 } | 196 } |
| 230 | 197 |
| 231 } // namespace ash | 198 } // namespace ash |
| OLD | NEW |