OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura/desktop.h" | 5 #include "ui/aura/desktop.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "ui/aura/aura_switches.h" | 16 #include "ui/aura/aura_switches.h" |
17 #include "ui/aura/desktop_delegate.h" | 17 #include "ui/aura/desktop_delegate.h" |
18 #include "ui/aura/desktop_host.h" | 18 #include "ui/aura/desktop_host.h" |
19 #include "ui/aura/desktop_observer.h" | 19 #include "ui/aura/desktop_observer.h" |
20 #include "ui/aura/event.h" | 20 #include "ui/aura/event.h" |
21 #include "ui/aura/event_filter.h" | 21 #include "ui/aura/event_filter.h" |
22 #include "ui/aura/focus_manager.h" | 22 #include "ui/aura/focus_manager.h" |
23 #include "ui/aura/screen_aura.h" | 23 #include "ui/aura/screen_aura.h" |
24 #include "ui/aura/screen_rotation.h" | |
25 #include "ui/aura/toplevel_window_container.h" | 24 #include "ui/aura/toplevel_window_container.h" |
26 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
27 #include "ui/aura/window_delegate.h" | 26 #include "ui/aura/window_delegate.h" |
28 #include "ui/gfx/compositor/compositor.h" | 27 #include "ui/gfx/compositor/compositor.h" |
29 #include "ui/gfx/compositor/layer.h" | 28 #include "ui/gfx/compositor/layer.h" |
30 #include "ui/gfx/compositor/layer_animation_sequence.h" | 29 #include "ui/gfx/compositor/layer_animation_sequence.h" |
31 #include "ui/gfx/compositor/layer_animator.h" | 30 #include "ui/gfx/compositor/layer_animator.h" |
| 31 #include "ui/gfx/compositor/screen_rotation.h" |
32 #include "ui/gfx/interpolated_transform.h" | 32 #include "ui/gfx/interpolated_transform.h" |
33 | 33 |
34 using std::string; | 34 using std::string; |
35 using std::vector; | 35 using std::vector; |
36 | 36 |
37 namespace aura { | 37 namespace aura { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // Default bounds for the host window. | 41 // Default bounds for the host window. |
42 static const int kDefaultHostWindowX = 200; | 42 static const int kDefaultHostWindowX = 200; |
43 static const int kDefaultHostWindowY = 200; | 43 static const int kDefaultHostWindowY = 200; |
44 static const int kDefaultHostWindowWidth = 1280; | 44 static const int kDefaultHostWindowWidth = 1280; |
45 static const int kDefaultHostWindowHeight = 1024; | 45 static const int kDefaultHostWindowHeight = 1024; |
46 | 46 |
47 #if !defined(NDEBUG) | |
48 // Converts degrees to an angle in the range [-180, 180). | |
49 int NormalizeAngle(int degrees) { | |
50 while (degrees <= -180) degrees += 360; | |
51 while (degrees > 180) degrees -= 360; | |
52 return degrees; | |
53 } | |
54 | |
55 static int SymmetricRound(float x) { | |
56 return static_cast<int>( | |
57 x > 0 | |
58 ? std::floor(x + 0.5f) | |
59 : std::ceil(x - 0.5f)); | |
60 } | |
61 #endif | |
62 | |
63 class DefaultDesktopDelegate : public DesktopDelegate { | 47 class DefaultDesktopDelegate : public DesktopDelegate { |
64 public: | 48 public: |
65 explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {} | 49 explicit DefaultDesktopDelegate(Desktop* desktop) : desktop_(desktop) {} |
66 virtual ~DefaultDesktopDelegate() {} | 50 virtual ~DefaultDesktopDelegate() {} |
67 | 51 |
68 private: | 52 private: |
69 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { | 53 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { |
70 desktop_->AddChild(window); | 54 desktop_->AddChild(window); |
71 } | 55 } |
72 | 56 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 145 |
162 bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { | 146 bool MaybeFullScreen(DesktopHost* host, KeyEvent* event) { |
163 if (event->key_code() == ui::VKEY_F11) { | 147 if (event->key_code() == ui::VKEY_F11) { |
164 host->ToggleFullScreen(); | 148 host->ToggleFullScreen(); |
165 return true; | 149 return true; |
166 } | 150 } |
167 return false; | 151 return false; |
168 } | 152 } |
169 | 153 |
170 bool MaybeRotate(Desktop* desktop, KeyEvent* event) { | 154 bool MaybeRotate(Desktop* desktop, KeyEvent* event) { |
171 if ((event->flags() & ui::EF_SHIFT_DOWN) && | 155 if ((event->flags() & ui::EF_CONTROL_DOWN) && |
172 (event->flags() & ui::EF_ALT_DOWN)) { | 156 event->key_code() == ui::VKEY_HOME) { |
173 bool should_rotate = true; | 157 static int i = 0; |
174 int new_degrees = 0; | 158 int delta = 0; |
175 switch (event->key_code()) { | 159 switch (i) { |
176 case ui::VKEY_UP: new_degrees = 0; break; | 160 case 0: delta = 90; break; |
177 case ui::VKEY_DOWN: new_degrees = 180; break; | 161 case 1: delta = 90; break; |
178 case ui::VKEY_RIGHT: new_degrees = 90; break; | 162 case 2: delta = 90; break; |
179 case ui::VKEY_LEFT: new_degrees = -90; break; | 163 case 3: delta = 90; break; |
180 default: should_rotate = false; break; | 164 case 4: delta = -90; break; |
| 165 case 5: delta = -90; break; |
| 166 case 6: delta = -90; break; |
| 167 case 7: delta = -90; break; |
| 168 case 8: delta = -90; break; |
| 169 case 9: delta = 180; break; |
| 170 case 10: delta = 180; break; |
| 171 case 11: delta = 90; break; |
| 172 case 12: delta = 180; break; |
| 173 case 13: delta = 180; break; |
181 } | 174 } |
182 | 175 i = (i + 1) % 14; |
183 if (should_rotate) { | 176 desktop->layer()->GetAnimator()->set_preemption_strategy( |
184 float rotation = 0.0f; | 177 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); |
185 int degrees = 0; | 178 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( |
186 const ui::Transform& transform = desktop->layer()->GetTargetTransform(); | 179 new ui::LayerAnimationSequence(new ui::ScreenRotation(delta))); |
187 if (ui::InterpolatedTransform::FactorTRS(transform, | 180 screen_rotation->AddObserver(desktop); |
188 NULL, &rotation, NULL)) | 181 desktop->layer()->GetAnimator()->ScheduleAnimation( |
189 degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation)); | 182 screen_rotation.release()); |
190 | 183 return true; |
191 if (degrees != 0) { | |
192 desktop->layer()->GetAnimator()->set_preemption_strategy( | |
193 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); | |
194 scoped_ptr<ui::LayerAnimationSequence> screen_rotation( | |
195 new ui::LayerAnimationSequence(new ScreenRotation(degrees))); | |
196 screen_rotation->AddObserver(desktop); | |
197 desktop->layer()->GetAnimator()->ScheduleAnimation( | |
198 screen_rotation.release()); | |
199 return true; | |
200 } | |
201 } | |
202 } | 184 } |
203 return false; | 185 return false; |
204 } | 186 } |
205 | 187 |
206 } // namespace | 188 } // namespace |
207 | 189 |
208 Desktop* Desktop::instance_ = NULL; | 190 Desktop* Desktop::instance_ = NULL; |
209 bool Desktop::use_fullscreen_host_window_ = false; | 191 bool Desktop::use_fullscreen_host_window_ = false; |
210 | 192 |
211 Desktop::Desktop() | 193 Desktop::Desktop() |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 614 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
633 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 615 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
634 } else if (use_fullscreen_host_window_) { | 616 } else if (use_fullscreen_host_window_) { |
635 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); | 617 bounds = gfx::Rect(DesktopHost::GetNativeDisplaySize()); |
636 } | 618 } |
637 | 619 |
638 return bounds; | 620 return bounds; |
639 } | 621 } |
640 | 622 |
641 } // namespace aura | 623 } // namespace aura |
OLD | NEW |