| 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/content/display/screen_orientation_controller_chromeos.h" |
| 7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 8 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
| 9 #include "ash/system/tray/tray_item_more.h" | 10 #include "ash/system/tray/tray_item_more.h" |
| 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 11 #include "grit/ash_resources.h" | 12 #include "grit/ash_resources.h" |
| 12 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace tray { | 20 namespace tray { |
| 20 | 21 |
| 21 // Extends TrayItemMore, however does not make use of the chevron, nor of the | 22 // Extends TrayItemMore, however does not make use of the chevron, nor of the |
| 22 // DetailedView. This was chosen over ActionableView in order to reuse the | 23 // DetailedView. This was chosen over ActionableView in order to reuse the |
| 23 // layout and styling of labels and images. This allows RotationLockDefaultView | 24 // layout and styling of labels and images. This allows RotationLockDefaultView |
| 24 // to maintain the look of other system tray items without code duplication. | 25 // to maintain the look of other system tray items without code duplication. |
| 25 class RotationLockDefaultView : public TrayItemMore, | 26 class RotationLockDefaultView : public TrayItemMore, |
| 26 public ShellObserver { | 27 public ShellObserver { |
| 27 public: | 28 public: |
| 28 explicit RotationLockDefaultView(SystemTrayItem* owner); | 29 explicit RotationLockDefaultView(SystemTrayItem* owner); |
| 29 virtual ~RotationLockDefaultView(); | 30 ~RotationLockDefaultView() override; |
| 30 | 31 |
| 31 // ActionableView: | 32 // ActionableView: |
| 32 virtual bool PerformAction(const ui::Event& event) override; | 33 bool PerformAction(const ui::Event& event) override; |
| 33 | 34 |
| 34 // ShellObserver: | 35 // ShellObserver: |
| 35 virtual void OnMaximizeModeStarted() override; | 36 void OnMaximizeModeStarted() override; |
| 36 virtual void OnMaximizeModeEnded() override; | 37 void OnMaximizeModeEnded() override; |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 void UpdateImage(); | 40 void UpdateImage(); |
| 40 | 41 |
| 41 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); | 42 DISALLOW_COPY_AND_ASSIGN(RotationLockDefaultView); |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) | 45 RotationLockDefaultView::RotationLockDefaultView(SystemTrayItem* owner) |
| 45 : TrayItemMore(owner, false) { | 46 : TrayItemMore(owner, false) { |
| 46 UpdateImage(); | 47 UpdateImage(); |
| 47 SetVisible(Shell::GetInstance()->maximize_mode_controller()-> | 48 SetVisible(Shell::GetInstance()->maximize_mode_controller()-> |
| 48 IsMaximizeModeWindowManagerEnabled()); | 49 IsMaximizeModeWindowManagerEnabled()); |
| 49 Shell::GetInstance()->AddShellObserver(this); | 50 Shell::GetInstance()->AddShellObserver(this); |
| 50 } | 51 } |
| 51 | 52 |
| 52 RotationLockDefaultView::~RotationLockDefaultView() { | 53 RotationLockDefaultView::~RotationLockDefaultView() { |
| 53 Shell::GetInstance()->RemoveShellObserver(this); | 54 Shell::GetInstance()->RemoveShellObserver(this); |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { | 57 bool RotationLockDefaultView::PerformAction(const ui::Event& event) { |
| 57 MaximizeModeController* maximize_mode_controller = Shell::GetInstance()-> | 58 ScreenOrientationController* screen_orientation_controller = |
| 58 maximize_mode_controller(); | 59 Shell::GetInstance()->screen_orientation_controller(); |
| 59 maximize_mode_controller->SetRotationLocked( | 60 screen_orientation_controller->SetRotationLocked( |
| 60 !maximize_mode_controller->rotation_locked()); | 61 !screen_orientation_controller->rotation_locked()); |
| 61 UpdateImage(); | 62 UpdateImage(); |
| 62 return true; | 63 return true; |
| 63 } | 64 } |
| 64 | 65 |
| 65 void RotationLockDefaultView::OnMaximizeModeStarted() { | 66 void RotationLockDefaultView::OnMaximizeModeStarted() { |
| 66 UpdateImage(); | 67 UpdateImage(); |
| 67 SetVisible(true); | 68 SetVisible(true); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void RotationLockDefaultView::OnMaximizeModeEnded() { | 71 void RotationLockDefaultView::OnMaximizeModeEnded() { |
| 71 SetVisible(false); | 72 SetVisible(false); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void RotationLockDefaultView::UpdateImage() { | 75 void RotationLockDefaultView::UpdateImage() { |
| 75 base::string16 label; | 76 base::string16 label; |
| 76 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 77 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 77 if (Shell::GetInstance()->maximize_mode_controller()->rotation_locked()) { | 78 if (Shell::GetInstance() |
| 79 ->screen_orientation_controller() |
| 80 ->rotation_locked()) { |
| 78 SetImage(bundle.GetImageNamed( | 81 SetImage(bundle.GetImageNamed( |
| 79 IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED_DARK).ToImageSkia()); | 82 IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED_DARK).ToImageSkia()); |
| 80 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED); | 83 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_LOCKED); |
| 81 SetLabel(label); | 84 SetLabel(label); |
| 82 SetAccessibleName(label); | 85 SetAccessibleName(label); |
| 83 } else { | 86 } else { |
| 84 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_AUTO_ROTATION_DARK). | 87 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_AUTO_ROTATION_DARK). |
| 85 ToImageSkia()); | 88 ToImageSkia()); |
| 86 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); | 89 label = l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ROTATION_LOCK_AUTO); |
| 87 SetLabel(label); | 90 SetLabel(label); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 } | 117 } |
| 115 | 118 |
| 116 views::View* TrayRotationLock::CreateDefaultView(user::LoginStatus status) { | 119 views::View* TrayRotationLock::CreateDefaultView(user::LoginStatus status) { |
| 117 if (on_primary_display_) | 120 if (on_primary_display_) |
| 118 return new tray::RotationLockDefaultView(this); | 121 return new tray::RotationLockDefaultView(this); |
| 119 return NULL; | 122 return NULL; |
| 120 } | 123 } |
| 121 | 124 |
| 122 void TrayRotationLock::OnMaximizeModeStarted() { | 125 void TrayRotationLock::OnMaximizeModeStarted() { |
| 123 tray_view()->SetVisible( | 126 tray_view()->SetVisible( |
| 124 Shell::GetInstance()->maximize_mode_controller()->rotation_locked()); | 127 Shell::GetInstance()->screen_orientation_controller()->rotation_locked()); |
| 125 Shell::GetInstance()->maximize_mode_controller()->AddObserver(this); | 128 Shell::GetInstance()->screen_orientation_controller()->AddObserver(this); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void TrayRotationLock::OnMaximizeModeEnded() { | 131 void TrayRotationLock::OnMaximizeModeEnded() { |
| 129 tray_view()->SetVisible(false); | 132 tray_view()->SetVisible(false); |
| 130 Shell::GetInstance()->maximize_mode_controller()->RemoveObserver(this); | 133 Shell::GetInstance()->screen_orientation_controller()->RemoveObserver(this); |
| 131 } | 134 } |
| 132 | 135 |
| 133 bool TrayRotationLock::GetInitialVisibility() { | 136 bool TrayRotationLock::GetInitialVisibility() { |
| 134 return ShouldBeVisible(); | 137 return ShouldBeVisible(); |
| 135 } | 138 } |
| 136 | 139 |
| 137 bool TrayRotationLock::ShouldBeVisible() { | 140 bool TrayRotationLock::ShouldBeVisible() { |
| 138 MaximizeModeController* controller = Shell::GetInstance()-> | |
| 139 maximize_mode_controller(); | |
| 140 return on_primary_display_ && | 141 return on_primary_display_ && |
| 141 controller->IsMaximizeModeWindowManagerEnabled() && | 142 Shell::GetInstance() |
| 142 controller->rotation_locked(); | 143 ->maximize_mode_controller() |
| 144 ->IsMaximizeModeWindowManagerEnabled() && |
| 145 Shell::GetInstance() |
| 146 ->screen_orientation_controller() |
| 147 ->rotation_locked(); |
| 143 } | 148 } |
| 144 | 149 |
| 145 } // namespace ash | 150 } // namespace ash |
| OLD | NEW |