| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/rotation/tray_rotation_lock.h" | 5 #include "ash/system/chromeos/rotation/tray_rotation_lock.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_item_more.h" | 10 #include "ash/common/system/tray/tray_item_more.h" |
| 11 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/display/screen_orientation_controller_chromeos.h" | 14 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 14 #include "ash/resources/vector_icons/vector_icons.h" | 15 #include "ash/resources/vector_icons/vector_icons.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
| 17 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 explicit RotationLockDefaultView(SystemTrayItem* owner); | 34 explicit RotationLockDefaultView(SystemTrayItem* owner); |
| 34 ~RotationLockDefaultView() override; | 35 ~RotationLockDefaultView() override; |
| 35 | 36 |
| 36 // ActionableView: | 37 // ActionableView: |
| 37 bool PerformAction(const ui::Event& event) override; | 38 bool PerformAction(const ui::Event& event) override; |
| 38 | 39 |
| 39 // ShellObserver: | 40 // ShellObserver: |
| 40 void OnMaximizeModeStarted() override; | 41 void OnMaximizeModeStarted() override; |
| 41 void OnMaximizeModeEnded() override; | 42 void OnMaximizeModeEnded() override; |
| 42 | 43 |
| 44 protected: |
| 45 // TrayItemMore: |
| 46 void UpdateStyle() override; |
| 47 |
| 43 private: | 48 private: |
| 44 void UpdateImage(); | 49 void UpdateImage(); |
| 45 | 50 |
| 46 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); | 51 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); |
| 47 }; | 52 }; |
| 48 | 53 |
| 49 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) | 54 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) |
| 50 : TrayItemMore(owner, false) { | 55 : TrayItemMore(owner, false) { |
| 51 UpdateImage(); | |
| 52 SetVisible(WmShell::Get() | 56 SetVisible(WmShell::Get() |
| 53 ->maximize_mode_controller() | 57 ->maximize_mode_controller() |
| 54 ->IsMaximizeModeWindowManagerEnabled()); | 58 ->IsMaximizeModeWindowManagerEnabled()); |
| 55 WmShell::Get()->AddShellObserver(this); | 59 WmShell::Get()->AddShellObserver(this); |
| 56 } | 60 } |
| 57 | 61 |
| 58 RotationLockDefaultView::~RotationLockDefaultView() { | 62 RotationLockDefaultView::~RotationLockDefaultView() { |
| 59 WmShell::Get()->RemoveShellObserver(this); | 63 WmShell::Get()->RemoveShellObserver(this); |
| 60 } | 64 } |
| 61 | 65 |
| 62 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { | 66 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { |
| 63 ScreenOrientationController* screen_orientation_controller = | 67 ScreenOrientationController* screen_orientation_controller = |
| 64 Shell::GetInstance()->screen_orientation_controller(); | 68 Shell::GetInstance()->screen_orientation_controller(); |
| 65 screen_orientation_controller->SetRotationLocked( | 69 screen_orientation_controller->SetRotationLocked( |
| 66 !screen_orientation_controller->rotation_locked()); | 70 !screen_orientation_controller->rotation_locked()); |
| 67 UpdateImage(); | 71 UpdateImage(); |
| 68 return true; | 72 return true; |
| 69 } | 73 } |
| 70 | 74 |
| 71 void RotationLockDefaultView::OnMaximizeModeStarted() { | 75 void RotationLockDefaultView::OnMaximizeModeStarted() { |
| 72 UpdateImage(); | 76 UpdateImage(); |
| 73 SetVisible(true); | 77 SetVisible(true); |
| 74 } | 78 } |
| 75 | 79 |
| 76 void RotationLockDefaultView::OnMaximizeModeEnded() { | 80 void RotationLockDefaultView::OnMaximizeModeEnded() { |
| 77 SetVisible(false); | 81 SetVisible(false); |
| 78 } | 82 } |
| 79 | 83 |
| 84 void RotationLockDefaultView::UpdateStyle() { |
| 85 TrayItemMore::UpdateStyle(); |
| 86 UpdateImage(); |
| 87 } |
| 88 |
| 80 void RotationLockDefaultView::UpdateImage() { | 89 void RotationLockDefaultView::UpdateImage() { |
| 81 const bool rotation_locked = | 90 const bool rotation_locked = |
| 82 Shell::GetInstance()->screen_orientation_controller()->rotation_locked(); | 91 Shell::GetInstance()->screen_orientation_controller()->rotation_locked(); |
| 83 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 92 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 93 std::unique_ptr<TrayPopupItemStyle> style = CreateStyle(); |
| 84 SetImage(gfx::CreateVectorIcon(rotation_locked | 94 SetImage(gfx::CreateVectorIcon(rotation_locked |
| 85 ? kSystemMenuRotationLockLockedIcon | 95 ? kSystemMenuRotationLockLockedIcon |
| 86 : kSystemMenuRotationLockAutoIcon, | 96 : kSystemMenuRotationLockAutoIcon, |
| 87 kMenuIconSize, kMenuIconColor)); | 97 kMenuIconSize, style->GetForegroundColor())); |
| 88 } else { | 98 } else { |
| 89 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 99 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 90 const int resource_id = rotation_locked | 100 const int resource_id = rotation_locked |
| 91 ? IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED_DARK | 101 ? IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED_DARK |
| 92 : IDR_AURA_UBER_TRAY_AUTO_ROTATION_DARK; | 102 : IDR_AURA_UBER_TRAY_AUTO_ROTATION_DARK; |
| 93 SetImage(*bundle.GetImageNamed(resource_id).ToImageSkia()); | 103 SetImage(*bundle.GetImageNamed(resource_id).ToImageSkia()); |
| 94 } | 104 } |
| 95 | 105 |
| 96 base::string16 label = l10n_util::GetStringUTF16( | 106 base::string16 label = l10n_util::GetStringUTF16( |
| 97 rotation_locked ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED | 107 rotation_locked ? IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 } | 185 } |
| 176 | 186 |
| 177 void TrayRotationLock::StopObservingShell() { | 187 void TrayRotationLock::StopObservingShell() { |
| 178 if (!observing_shell_) | 188 if (!observing_shell_) |
| 179 return; | 189 return; |
| 180 WmShell::Get()->RemoveShellObserver(this); | 190 WmShell::Get()->RemoveShellObserver(this); |
| 181 observing_shell_ = false; | 191 observing_shell_ = false; |
| 182 } | 192 } |
| 183 | 193 |
| 184 } // namespace ash | 194 } // namespace ash |
| OLD | NEW |