| 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/system/status_area_widget_delegate.h" | 5 #include "ash/system/status_area_widget_delegate.h" |
| 6 | 6 |
| 7 #include "ash/focus_cycler.h" | 7 #include "ash/focus_cycler.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/session/session_controller.h" | 9 #include "ash/session/session_controller.h" |
| 10 #include "ash/shelf/shelf.h" |
| 10 #include "ash/shelf/shelf_constants.h" | 11 #include "ash/shelf/shelf_constants.h" |
| 11 #include "ash/shelf/wm_shelf.h" | |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/system/status_area_widget.h" | 13 #include "ash/system/status_area_widget.h" |
| 14 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
| 15 #include "ash/system/tray/tray_constants.h" | 15 #include "ash/system/tray/tray_constants.h" |
| 16 #include "ash/wm_window.h" | 16 #include "ash/wm_window.h" |
| 17 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/animation/tween.h" | 19 #include "ui/gfx/animation/tween.h" |
| 20 #include "ui/views/accessible_pane_view.h" | 20 #include "ui/views/accessible_pane_view.h" |
| 21 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 52 | 52 |
| 53 // static | 53 // static |
| 54 StatusAreaWidgetDelegate* StatusAreaWidgetDelegate::GetPrimaryInstance() { | 54 StatusAreaWidgetDelegate* StatusAreaWidgetDelegate::GetPrimaryInstance() { |
| 55 SystemTray* tray = Shell::Get()->GetPrimarySystemTray(); | 55 SystemTray* tray = Shell::Get()->GetPrimarySystemTray(); |
| 56 return tray ? tray->shelf() | 56 return tray ? tray->shelf() |
| 57 ->GetStatusAreaWidget() | 57 ->GetStatusAreaWidget() |
| 58 ->status_area_widget_delegate() | 58 ->status_area_widget_delegate() |
| 59 : nullptr; | 59 : nullptr; |
| 60 } | 60 } |
| 61 | 61 |
| 62 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate(WmShelf* wm_shelf) | 62 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate(Shelf* shelf) |
| 63 : wm_shelf_(wm_shelf), focus_cycler_for_testing_(nullptr) { | 63 : shelf_(shelf), focus_cycler_for_testing_(nullptr) { |
| 64 DCHECK(wm_shelf_); | 64 DCHECK(shelf_); |
| 65 | 65 |
| 66 // Allow the launcher to surrender the focus to another window upon | 66 // Allow the launcher to surrender the focus to another window upon |
| 67 // navigation completion by the user. | 67 // navigation completion by the user. |
| 68 set_allow_deactivate_on_esc(true); | 68 set_allow_deactivate_on_esc(true); |
| 69 SetPaintToLayer(); | 69 SetPaintToLayer(); |
| 70 layer()->SetFillsBoundsOpaquely(false); | 70 layer()->SetFillsBoundsOpaquely(false); |
| 71 } | 71 } |
| 72 | 72 |
| 73 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() {} | 73 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() {} |
| 74 | 74 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 97 return View::GetWidget(); | 97 return View::GetWidget(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 const views::Widget* StatusAreaWidgetDelegate::GetWidget() const { | 100 const views::Widget* StatusAreaWidgetDelegate::GetWidget() const { |
| 101 return View::GetWidget(); | 101 return View::GetWidget(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void StatusAreaWidgetDelegate::OnGestureEvent(ui::GestureEvent* event) { | 104 void StatusAreaWidgetDelegate::OnGestureEvent(ui::GestureEvent* event) { |
| 105 views::Widget* target_widget = | 105 views::Widget* target_widget = |
| 106 static_cast<views::View*>(event->target())->GetWidget(); | 106 static_cast<views::View*>(event->target())->GetWidget(); |
| 107 WmShelf* shelf = WmShelf::ForWindow(target_widget->GetNativeWindow()); | 107 Shelf* shelf = Shelf::ForWindow(target_widget->GetNativeWindow()); |
| 108 if (shelf->ProcessGestureEvent(*event)) | 108 if (shelf->ProcessGestureEvent(*event)) |
| 109 event->StopPropagation(); | 109 event->StopPropagation(); |
| 110 else | 110 else |
| 111 views::AccessiblePaneView::OnGestureEvent(event); | 111 views::AccessiblePaneView::OnGestureEvent(event); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool StatusAreaWidgetDelegate::CanActivate() const { | 114 bool StatusAreaWidgetDelegate::CanActivate() const { |
| 115 // We don't want mouse clicks to activate us, but we need to allow | 115 // We don't want mouse clicks to activate us, but we need to allow |
| 116 // activation when the user is using the keyboard (FocusCycler). | 116 // activation when the user is using the keyboard (FocusCycler). |
| 117 const FocusCycler* focus_cycler = focus_cycler_for_testing_ | 117 const FocusCycler* focus_cycler = focus_cycler_for_testing_ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 140 for (int c = 0; c < child_count(); ++c) { | 140 for (int c = 0; c < child_count(); ++c) { |
| 141 views::View* child = child_at(c); | 141 views::View* child = child_at(c); |
| 142 if (!child->visible()) | 142 if (!child->visible()) |
| 143 continue; | 143 continue; |
| 144 SetBorderOnChild(child, is_child_on_edge); | 144 SetBorderOnChild(child, is_child_on_edge); |
| 145 is_child_on_edge = false; | 145 is_child_on_edge = false; |
| 146 } | 146 } |
| 147 | 147 |
| 148 views::ColumnSet* columns = layout->AddColumnSet(0); | 148 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 149 | 149 |
| 150 if (wm_shelf_->IsHorizontalAlignment()) { | 150 if (shelf_->IsHorizontalAlignment()) { |
| 151 for (int c = child_count() - 1; c >= 0; --c) { | 151 for (int c = child_count() - 1; c >= 0; --c) { |
| 152 views::View* child = child_at(c); | 152 views::View* child = child_at(c); |
| 153 if (!child->visible()) | 153 if (!child->visible()) |
| 154 continue; | 154 continue; |
| 155 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, | 155 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, |
| 156 0, /* resize percent */ | 156 0, /* resize percent */ |
| 157 views::GridLayout::USE_PREF, 0, 0); | 157 views::GridLayout::USE_PREF, 0, 0); |
| 158 } | 158 } |
| 159 layout->StartRow(0, 0); | 159 layout->StartRow(0, 0); |
| 160 for (int c = child_count() - 1; c >= 0; --c) { | 160 for (int c = child_count() - 1; c >= 0; --c) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 195 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
| 196 if (GetWidget()) | 196 if (GetWidget()) |
| 197 GetWidget()->SetSize(GetPreferredSize()); | 197 GetWidget()->SetSize(GetPreferredSize()); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, | 200 void StatusAreaWidgetDelegate::SetBorderOnChild(views::View* child, |
| 201 bool extend_border_to_edge) { | 201 bool extend_border_to_edge) { |
| 202 // Tray views are laid out right-to-left or bottom-to-top. | 202 // Tray views are laid out right-to-left or bottom-to-top. |
| 203 const bool horizontal_alignment = wm_shelf_->IsHorizontalAlignment(); | 203 const bool horizontal_alignment = shelf_->IsHorizontalAlignment(); |
| 204 const int padding = (kShelfSize - kTrayItemSize) / 2; | 204 const int padding = (kShelfSize - kTrayItemSize) / 2; |
| 205 | 205 |
| 206 const int top_edge = horizontal_alignment ? padding : 0; | 206 const int top_edge = horizontal_alignment ? padding : 0; |
| 207 const int left_edge = horizontal_alignment ? 0 : padding; | 207 const int left_edge = horizontal_alignment ? 0 : padding; |
| 208 const int bottom_edge = | 208 const int bottom_edge = |
| 209 horizontal_alignment | 209 horizontal_alignment |
| 210 ? padding | 210 ? padding |
| 211 : (extend_border_to_edge ? kPaddingFromEdgeOfShelf : 0); | 211 : (extend_border_to_edge ? kPaddingFromEdgeOfShelf : 0); |
| 212 const int right_edge = | 212 const int right_edge = |
| 213 horizontal_alignment | 213 horizontal_alignment |
| 214 ? (extend_border_to_edge ? kPaddingFromEdgeOfShelf : 0) | 214 ? (extend_border_to_edge ? kPaddingFromEdgeOfShelf : 0) |
| 215 : padding; | 215 : padding; |
| 216 child->SetBorder( | 216 child->SetBorder( |
| 217 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); | 217 views::CreateEmptyBorder(top_edge, left_edge, bottom_edge, right_edge)); |
| 218 | 218 |
| 219 // Layout on |child| needs to be updated based on new border value before | 219 // Layout on |child| needs to be updated based on new border value before |
| 220 // displaying; otherwise |child| will be showing with old border size. | 220 // displaying; otherwise |child| will be showing with old border size. |
| 221 // Fix for crbug.com/623438. | 221 // Fix for crbug.com/623438. |
| 222 child->Layout(); | 222 child->Layout(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace ash | 225 } // namespace ash |
| OLD | NEW |