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

Side by Side Diff: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc

Issue 7273073: Animated Rotation (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Moved screen rotation code under touch; use lock object to disable painting Created 9 years, 4 months 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 "chrome/browser/ui/touch/frame/touch_browser_frame_view.h" 5 #include "chrome/browser/ui/touch/frame/touch_browser_frame_view.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" 8 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
9 #include "chrome/browser/tabs/tab_strip_model.h" 9 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/ui/touch/animation/screen_rotation_setter.h"
12 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h" 13 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h" 15 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
15 #include "chrome/common/chrome_notification_types.h" 16 #include "chrome/common/chrome_notification_types.h"
16 #include "content/browser/renderer_host/render_view_host.h" 17 #include "content/browser/renderer_host/render_view_host.h"
17 #include "content/browser/tab_contents/navigation_controller.h" 18 #include "content/browser/tab_contents/navigation_controller.h"
18 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/browser/tab_contents/tab_contents_view.h" 20 #include "content/browser/tab_contents/tab_contents_view.h"
20 #include "content/common/content_notification_types.h" 21 #include "content/common/content_notification_types.h"
21 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
22 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
23 #include "ui/base/animation/slide_animation.h" 24 #include "ui/base/animation/slide_animation.h"
24 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
25 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
27 #include "views/desktop/desktop_window_view.h"
26 #include "views/controls/button/image_button.h" 28 #include "views/controls/button/image_button.h"
27 #include "views/controls/textfield/textfield.h" 29 #include "views/controls/textfield/textfield.h"
28 #include "views/focus/focus_manager.h" 30 #include "views/focus/focus_manager.h"
29 #include "views/window/hit_test.h" 31 #include "views/window/hit_test.h"
30 32
31 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
32 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" 34 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h"
33 #endif 35 #endif
34 36
35 namespace { 37 namespace {
36 38
37 const int kDefaultKeyboardHeight = 300; 39 const int kDefaultKeyboardHeight = 300;
38 const int kKeyboardSlideDuration = 300; // In milliseconds 40 const int kKeyboardSlideDuration = 300; // In milliseconds
39 41
40 PropertyAccessor<bool>* GetFocusedStateAccessor() { 42 PropertyAccessor<bool>* GetFocusedStateAccessor() {
41 static PropertyAccessor<bool> state; 43 static PropertyAccessor<bool> state;
42 return &state; 44 return &state;
43 } 45 }
44 46
45 bool TabContentsHasFocus(const TabContents* contents) { 47 bool TabContentsHasFocus(const TabContents* contents) {
46 views::View* view = static_cast<TabContentsViewTouch*>(contents->view()); 48 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
47 return view->Contains(view->GetFocusManager()->GetFocusedView()); 49 return view->Contains(view->GetFocusManager()->GetFocusedView());
48 } 50 }
49 51
52 ui::Transform SideToTransform(sensors::ScreenOrientation::Side side,
53 const ui::Transform& old_transform,
54 const gfx::Size& size) {
55 gfx::Point origin;
56 gfx::Point bottom_right(size.width(), size.height());
57 old_transform.TransformPoint(origin);
58 old_transform.TransformPoint(bottom_right);
59 int original_width = abs(origin.x() - bottom_right.x());
60 int original_height = abs(origin.y() - bottom_right.y());
61 ui::Transform to_return;
62 switch (side) {
63 case sensors::ScreenOrientation::TOP: break;
64 case sensors::ScreenOrientation::RIGHT:
65 to_return.ConcatRotate(90);
66 to_return.ConcatTranslate(original_width, 0);
67 break;
68 case sensors::ScreenOrientation::LEFT:
69 to_return.ConcatRotate(-90);
70 to_return.ConcatTranslate(0, original_height);
71 break;
72 case sensors::ScreenOrientation::BOTTOM:
73 to_return.ConcatRotate(180);
74 to_return.ConcatTranslate(original_width, original_height);
75 break;
76 default:
77 to_return = old_transform;
78 break;
79 }
80 return to_return;
81 }
82
50 } // namespace 83 } // namespace
51 84
52 // static 85 // static
53 const char TouchBrowserFrameView::kViewClassName[] = 86 const char TouchBrowserFrameView::kViewClassName[] =
54 "browser/ui/touch/frame/TouchBrowserFrameView"; 87 "browser/ui/touch/frame/TouchBrowserFrameView";
55 88
56 /////////////////////////////////////////////////////////////////////////////// 89 ///////////////////////////////////////////////////////////////////////////////
57 // TouchBrowserFrameView, public: 90 // TouchBrowserFrameView, public:
58 91
59 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 92 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
(...skipping 26 matching lines...) Expand all
86 119
87 animation_.reset(new ui::SlideAnimation(this)); 120 animation_.reset(new ui::SlideAnimation(this));
88 animation_->SetTweenType(ui::Tween::LINEAR); 121 animation_->SetTweenType(ui::Tween::LINEAR);
89 animation_->SetSlideDuration(kKeyboardSlideDuration); 122 animation_->SetSlideDuration(kKeyboardSlideDuration);
90 123
91 #if defined(OS_CHROMEOS) 124 #if defined(OS_CHROMEOS)
92 chromeos::input_method::InputMethodManager* manager = 125 chromeos::input_method::InputMethodManager* manager =
93 chromeos::input_method::InputMethodManager::GetInstance(); 126 chromeos::input_method::InputMethodManager::GetInstance();
94 manager->AddVirtualKeyboardObserver(this); 127 manager->AddVirtualKeyboardObserver(this);
95 #endif 128 #endif
129
130 sensors::Provider::GetInstance()->AddListener(this);
96 } 131 }
97 132
98 TouchBrowserFrameView::~TouchBrowserFrameView() { 133 TouchBrowserFrameView::~TouchBrowserFrameView() {
99 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 134 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
135 sensors::Provider::GetInstance()->RemoveListener(this);
100 } 136 }
101 137
102 int TouchBrowserFrameView::NonClientHitTest(const gfx::Point& point) { 138 int TouchBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
103 if (keyboard_->GetMirroredBounds().Contains(point)) 139 if (keyboard_->GetMirroredBounds().Contains(point))
104 return HTCLIENT; 140 return HTCLIENT;
105 return OpaqueBrowserFrameView::NonClientHitTest(point); 141 return OpaqueBrowserFrameView::NonClientHitTest(point);
106 } 142 }
107 143
108 std::string TouchBrowserFrameView::GetClassName() const { 144 std::string TouchBrowserFrameView::GetClassName() const {
109 return kViewClassName; 145 return kViewClassName;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 398 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
363 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( 399 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView(
364 host->routing_id())); 400 host->routing_id()));
365 } else { 401 } else {
366 // Notify the keyboard that it is hidden now. 402 // Notify the keyboard that it is hidden now.
367 keyboard_->SetVisible(false); 403 keyboard_->SetVisible(false);
368 } 404 }
369 SchedulePaint(); 405 SchedulePaint();
370 } 406 }
371 407
408 void TouchBrowserFrameView::OnScreenOrientationChanged(
409 const sensors::ScreenOrientation& change) {
410 views::View* to_rotate =
411 views::desktop::DesktopWindowView::desktop_window_view;
412
413 if (!to_rotate) {
414 views::Widget* widget = GetWidget();
415 to_rotate = widget->GetRootView();
416 }
417
418 if (!setter_) {
419 setter_ = ScreenRotationSetterFactory::Create(to_rotate);
420 to_rotate->SetLayerPropertySetter(setter_);
421 }
422
423 ui::Transform xform = SideToTransform(change.upward,
424 to_rotate->GetTransform(),
425 to_rotate->size());
426 to_rotate->SetTransform(xform);
427 }
428
372 #if defined(OS_CHROMEOS) 429 #if defined(OS_CHROMEOS)
373 void TouchBrowserFrameView::VirtualKeyboardChanged( 430 void TouchBrowserFrameView::VirtualKeyboardChanged(
374 chromeos::input_method::InputMethodManager* manager, 431 chromeos::input_method::InputMethodManager* manager,
375 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, 432 const chromeos::input_method::VirtualKeyboard& virtual_keyboard,
376 const std::string& virtual_keyboard_layout) { 433 const std::string& virtual_keyboard_layout) {
377 const GURL& new_url = 434 const GURL& new_url =
378 virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); 435 virtual_keyboard.GetURLForLayout(virtual_keyboard_layout);
379 if (new_url == url_) 436 if (new_url == url_)
380 return; 437 return;
381 438
382 url_ = new_url; 439 url_ = new_url;
383 if (keyboard_) 440 if (keyboard_)
384 keyboard_->LoadURL(url_); 441 keyboard_->LoadURL(url_);
385 // |keyboard_| can be NULL here. In that case, the |url_| will be used in 442 // |keyboard_| can be NULL here. In that case, the |url_| will be used in
386 // InitVirtualKeyboard() later. 443 // InitVirtualKeyboard() later.
387 } 444 }
388 #endif 445 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698