Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: ui/aura/desktop.cc

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Enable framework for aura Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/focus_manager.h" 21 #include "ui/aura/focus_manager.h"
22 #include "ui/aura/screen_aura.h" 22 #include "ui/aura/screen_aura.h"
23 #include "ui/aura/screen_rotation.h"
23 #include "ui/aura/toplevel_window_container.h" 24 #include "ui/aura/toplevel_window_container.h"
24 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
25 #include "ui/aura/window_delegate.h" 26 #include "ui/aura/window_delegate.h"
26 #include "ui/gfx/compositor/compositor.h" 27 #include "ui/gfx/compositor/compositor.h"
27 #include "ui/gfx/compositor/layer.h" 28 #include "ui/gfx/compositor/layer.h"
29 #include "ui/gfx/compositor/layer_animation_sequence.h"
30 #include "ui/gfx/compositor/layer_animator.h"
31 #include "ui/gfx/interpolated_transform.h"
28 32
29 using std::string; 33 using std::string;
30 using std::vector; 34 using std::vector;
31 35
32 namespace aura { 36 namespace aura {
33 37
34 namespace { 38 namespace {
35 39
36 // Default bounds for the host window. 40 // Default bounds for the host window.
37 static const int kDefaultHostWindowX = 200; 41 static const int kDefaultHostWindowX = 200;
38 static const int kDefaultHostWindowY = 200; 42 static const int kDefaultHostWindowY = 200;
39 static const int kDefaultHostWindowWidth = 1280; 43 static const int kDefaultHostWindowWidth = 1280;
40 static const int kDefaultHostWindowHeight = 1024; 44 static const int kDefaultHostWindowHeight = 1024;
41 45
46 // Converts degrees to an angle in the range [-180, 180).
47 int NormalizeAngle(int degrees) {
48 while (degrees <= -180) degrees += 360;
49 while (degrees > 180) degrees -= 360;
50 return degrees;
51 }
52
53 static int SymmetricRound(float x) {
54 return static_cast<int>(
55 x > 0
56 ? std::floor(x + 0.5f)
57 : std::ceil(x - 0.5f));
58 }
59
42 } // namespace 60 } // namespace
43 61
44 // static 62 // static
45 Desktop* Desktop::instance_ = NULL; 63 Desktop* Desktop::instance_ = NULL;
46 64
47 // static 65 // static
48 ui::Compositor*(*Desktop::compositor_factory_)() = NULL; 66 ui::Compositor*(*Desktop::compositor_factory_)() = NULL;
49 67
50 Desktop::Desktop() 68 Desktop::Desktop()
51 : Window(NULL), 69 : Window(NULL),
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 170 }
153 if (target && target->delegate()) { 171 if (target && target->delegate()) {
154 MouseEvent translated_event(*event, this, target); 172 MouseEvent translated_event(*event, this, target);
155 return target->OnMouseEvent(&translated_event); 173 return target->OnMouseEvent(&translated_event);
156 } 174 }
157 return false; 175 return false;
158 } 176 }
159 177
160 bool Desktop::DispatchKeyEvent(KeyEvent* event) { 178 bool Desktop::DispatchKeyEvent(KeyEvent* event) {
161 #if !defined(NDEBUG) 179 #if !defined(NDEBUG)
162 // Press Home key to rotate the screen. Primarily used for testing.
163 if (event->type() == ui::ET_KEY_PRESSED && 180 if (event->type() == ui::ET_KEY_PRESSED &&
164 (event->flags() & ui::EF_CONTROL_DOWN) && 181 (event->flags() & ui::EF_SHIFT_DOWN) &&
165 event->key_code() == ui::VKEY_HOME) { 182 (event->flags() & ui::EF_ALT_DOWN) &&
166 ui::Transform transform; 183 event->is_char()) {
167 static int count = 0; 184
168 gfx::Size size = host_->GetSize(); 185 bool should_rotate = true;
169 switch (count) { 186 int new_degrees = 0;
170 case 0: 187 switch (event->key_code()) {
171 transform.ConcatRotate(-90.0f); 188 case ui::VKEY_UP: new_degrees = 0; break;
172 transform.ConcatTranslate(0, size.height()); 189 case ui::VKEY_DOWN: new_degrees = 180; break;
173 break; 190 case ui::VKEY_RIGHT: new_degrees = 90; break;
174 case 1: 191 case ui::VKEY_LEFT: new_degrees = -90; break;
175 transform.ConcatRotate(180.0f); 192 default: should_rotate = false; break;
176 transform.ConcatTranslate(size.width(), size.height());
177 break;
178 case 2:
179 transform.ConcatRotate(90.0f);
180 transform.ConcatTranslate(size.width(), 0);
181 break;
182 } 193 }
183 layer()->SetAnimation(CreateDefaultAnimation()); 194
184 SetTransform(transform); 195 if (should_rotate) {
185 count = (count + 1) % 4; 196 float rotation = 0.0f;
186 return true; 197 int degrees = 0;
198 const ui::Transform& transform = layer()->GetTargetTransform();
199 if (ui::InterpolatedTransform::FactorTRS(transform,
200 NULL, &rotation, NULL))
201 degrees = NormalizeAngle(new_degrees - SymmetricRound(rotation));
202
203 if (degrees != 0) {
204 layer()->GetAnimator()->set_preemption_strategy(
205 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
206 layer()->GetAnimator()->ScheduleAnimation(new ScreenRotation(degrees));
207 return true;
208 }
209 }
187 } 210 }
188 #endif 211 #endif
189 212
190 if (focused_window_) { 213 if (focused_window_) {
191 KeyEvent translated_event(*event); 214 KeyEvent translated_event(*event);
192 return focused_window_->OnKeyEvent(&translated_event); 215 return focused_window_->OnKeyEvent(&translated_event);
193 } 216 }
194 return false; 217 return false;
195 } 218 }
196 219
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (capture_window_ && capture_window_->delegate()) 358 if (capture_window_ && capture_window_->delegate())
336 capture_window_->delegate()->OnCaptureLost(); 359 capture_window_->delegate()->OnCaptureLost();
337 capture_window_ = NULL; 360 capture_window_ = NULL;
338 } 361 }
339 362
340 void Desktop::SetTransform(const ui::Transform& transform) { 363 void Desktop::SetTransform(const ui::Transform& transform) {
341 Window::SetTransform(transform); 364 Window::SetTransform(transform);
342 365
343 // If the layer is not animating, then we need to update the host size 366 // If the layer is not animating, then we need to update the host size
344 // immediately. 367 // immediately.
345 if (!layer()->has_animation()) 368 if (!layer()->GetAnimator()->is_animating())
346 OnHostResized(host_->GetSize()); 369 OnHostResized(host_->GetSize());
347 } 370 }
348 371
349 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { 372 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) {
350 if (target == mouse_moved_handler_) 373 if (target == mouse_moved_handler_)
351 return; 374 return;
352 375
353 // Send an exited event. 376 // Send an exited event.
354 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { 377 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) {
355 MouseEvent translated_event(event, this, mouse_moved_handler_, 378 MouseEvent translated_event(event, this, mouse_moved_handler_,
(...skipping 22 matching lines...) Expand all
378 } 401 }
379 402
380 internal::FocusManager* Desktop::GetFocusManager() { 403 internal::FocusManager* Desktop::GetFocusManager() {
381 return this; 404 return this;
382 } 405 }
383 406
384 Desktop* Desktop::GetDesktop() { 407 Desktop* Desktop::GetDesktop() {
385 return this; 408 return this;
386 } 409 }
387 410
388 void Desktop::OnLayerAnimationEnded(const ui::Animation* animation) { 411 void Desktop::OnLayerAnimationEnded(
412 const ui::LayerAnimationSequence* animation) {
389 OnHostResized(host_->GetSize()); 413 OnHostResized(host_->GetSize());
390 } 414 }
391 415
392 void Desktop::SetFocusedWindow(Window* focused_window) { 416 void Desktop::SetFocusedWindow(Window* focused_window) {
393 if (focused_window == focused_window_ || 417 if (focused_window == focused_window_ ||
394 (focused_window && !focused_window->CanFocus())) { 418 (focused_window && !focused_window->CanFocus())) {
395 return; 419 return;
396 } 420 }
397 if (focused_window_ && focused_window_->delegate()) 421 if (focused_window_ && focused_window_->delegate())
398 focused_window_->delegate()->OnBlur(); 422 focused_window_->delegate()->OnBlur();
(...skipping 28 matching lines...) Expand all
427 !base::StringToInt(parts[0], &width) || 451 !base::StringToInt(parts[0], &width) ||
428 !base::StringToInt(parts[1], &height) || 452 !base::StringToInt(parts[1], &height) ||
429 width <= 0 || height <= 0) { 453 width <= 0 || height <= 0) {
430 width = kDefaultHostWindowWidth; 454 width = kDefaultHostWindowWidth;
431 height = kDefaultHostWindowHeight; 455 height = kDefaultHostWindowHeight;
432 } 456 }
433 return gfx::Rect(kDefaultHostWindowX, kDefaultHostWindowY, width, height); 457 return gfx::Rect(kDefaultHostWindowX, kDefaultHostWindowY, width, height);
434 } 458 }
435 459
436 } // namespace aura 460 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/desktop.h ('k') | ui/aura/screen_rotation.h » ('j') | ui/gfx/compositor/layer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698