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

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: Use new minimal sensor API Created 9 years, 5 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 "base/debug/trace_event.h"
7 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" 9 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
9 #include "chrome/browser/tabs/tab_strip_model.h" 10 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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/gfx/interpolated_transform.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"
26 #include "views/controls/button/image_button.h" 27 #include "views/controls/button/image_button.h"
27 #include "views/controls/textfield/textfield.h" 28 #include "views/controls/textfield/textfield.h"
28 #include "views/focus/focus_manager.h" 29 #include "views/focus/focus_manager.h"
29 30
30 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" 32 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h"
32 #endif 33 #endif
33 34
34 namespace { 35 namespace {
35 36
36 const int kDefaultKeyboardHeight = 300; 37 const int kDefaultKeyboardHeight = 300;
37 const int kKeyboardSlideDuration = 300; // In milliseconds 38 const int kKeyboardSlideDuration = 300; // In milliseconds
38 39
39 PropertyAccessor<bool>* GetFocusedStateAccessor() { 40 PropertyAccessor<bool>* GetFocusedStateAccessor() {
40 static PropertyAccessor<bool> state; 41 static PropertyAccessor<bool> state;
41 return &state; 42 return &state;
42 } 43 }
43 44
44 bool TabContentsHasFocus(const TabContents* contents) { 45 bool TabContentsHasFocus(const TabContents* contents) {
45 views::View* view = static_cast<TabContentsViewTouch*>(contents->view()); 46 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
46 return view->Contains(view->GetFocusManager()->GetFocusedView()); 47 return view->Contains(view->GetFocusManager()->GetFocusedView());
47 } 48 }
48 49
49 } // namespace 50 } // namespace
50 51
52 ////////////////////////////////////////////////////////////////////////////////
53 // Animation
54
55 class TouchBrowserFrameRotation : public ui::AnimationDelegate {
sadrul 2011/07/15 15:25:48 This probably should be in the anonymous namespace
56 public:
57 static void Perform(views::View* root,
58 sensors::ScreenOrientation::Side oldUp,
59 sensors::ScreenOrientation::Side newUp) {
60 new TouchBrowserFrameRotation(root, oldUp, newUp);
61 }
62
63 private:
64 TouchBrowserFrameRotation(views::View* root,
65 sensors::ScreenOrientation::Side old_up,
66 sensors::ScreenOrientation::Side new_up)
67 : root_(root),
sadrul 2011/07/15 15:25:48 4-space indent
68 old_up_(old_up),
69 new_up_(new_up) {
70 animation_.reset(new ui::SlideAnimation(this));
71 animation_->SetTweenType(ui::Tween::LINEAR);
72 animation_->SetSlideDuration(1000);
73 Start();
74 }
75
76 virtual void AnimationProgressed(const ui::Animation* anim) OVERRIDE {
77 if (!interpolated_transform_.get())
78 return;
79
80 float t = static_cast<float>(anim->GetCurrentValue());
81 root_->SetTransform(interpolated_transform_->Interpolate(t));
82 root_->ScheduleComposite();
83 }
84
85 virtual void AnimationEnded(const ui::Animation* anim) OVERRIDE {
86 TRACE_EVENT_END0("RotateAnimation", "Start rotating");
87 // TODO(vollick) massage matrix so that entries sufficiently close
88 // to 0, 1, or -1 are clamped to these values. The idea is to fight
89 // accumulated numeric error due to successive rotations.
90 ui::Transform xform = root_->GetTransform();
91 gfx::Point origin;
92 xform.TransformPoint(origin);
93 ui::Transform translation;
94 translation.SetTranslate(new_origin_.x() - origin.x(),
95 new_origin_.y() - origin.y());
96 xform.ConcatTransform(translation);
97 root_->SetTransform(xform);
98 root_->SetBounds(0, 0, new_size_.width(), new_size_.height());
99 root_->SetPaintingEnabled(true);
100 root_->SchedulePaint();
101 delete this;
102 }
103
104 int SideToDegrees(sensors::ScreenOrientation::Side side) {
105 switch (side) {
106 case sensors::ScreenOrientation::RIGHT: return 90;
sadrul 2011/07/15 15:25:48 indentations!
107 case sensors::ScreenOrientation::LEFT: return -90;
108 case sensors::ScreenOrientation::BOTTOM: return 180;
109 default: return 0;
110 }
111 }
112
113 int NormalizeAngle(int degrees) {
114 while (degrees <= -180) degrees += 360;
115 while (degrees > 180) degrees -= 360;
116 return degrees;
117 }
118
119 void Start() {
120 TRACE_EVENT_BEGIN0("RotateAnimation", "Start rotating");
121 root_->SetPaintingEnabled(false);
122 int degrees = SideToDegrees(new_up_) - SideToDegrees(old_up_);
123 degrees = NormalizeAngle(degrees);
124
125 // No rotation required.
126 if (degrees == 0)
127 return;
128
129 gfx::Point old_pivot;
130 gfx::Point new_pivot;
131
132 switch (degrees) {
133 case 90:
sadrul 2011/07/15 15:25:48 ditto
134 new_origin_ = old_pivot = gfx::Point(root_->width(), 0);
135 new_pivot.SetPoint(root_->width(), root_->height());
136 new_size_.SetSize(root_->height(), root_->width());
137 break;
138 case -90:
139 new_origin_ = new_pivot = gfx::Point(0, root_->height());
140 new_size_.SetSize(root_->height(), root_->width());
141 break;
142 case 180:
143 new_pivot = old_pivot = gfx::Point(root_->width() / 2,
144 root_->height() / 2);
145 new_origin_.SetPoint(root_->width(), root_->height());
146 new_size_.SetSize(root_->width(), root_->height());
147 break;
148 }
149
150 // Convert points to world space.
151 const ui::Transform& xform = root_->GetTransform();
152 xform.TransformPoint(old_pivot);
153 xform.TransformPoint(new_pivot);
154 xform.TransformPoint(new_origin_);
155
156 scoped_ptr<ui::InterpolatedTransform> rotation(
157 new ui::InterpolatedTransformAboutPivot(
158 old_pivot,
159 new ui::InterpolatedRotation(0, degrees)));
160
161 scoped_ptr<ui::InterpolatedTransform> translation(
162 new ui::InterpolatedTranslation(
163 gfx::Point(0, 0),
164 gfx::Point(new_pivot.x() - old_pivot.x(),
165 new_pivot.y() - old_pivot.y())));
166
167 interpolated_transform_.reset(
168 new ui::InterpolatedConstantTransform(xform));
169
170 rotation->SetChild(translation.release());
171 interpolated_transform_->SetChild(rotation.release());
172
173 animation_->Show();
174 }
175
176 views::View* root_;
177 scoped_ptr<ui::SlideAnimation> animation_;
178 scoped_ptr<ui::InterpolatedTransform> interpolated_transform_;
179 sensors::ScreenOrientation::Side old_up_;
180 sensors::ScreenOrientation::Side new_up_;
181 gfx::Size new_size_;
182 gfx::Point new_origin_;
183
184 DISALLOW_COPY_AND_ASSIGN(TouchBrowserFrameRotation);
185 };
186
51 // static 187 // static
52 const char TouchBrowserFrameView::kViewClassName[] = 188 const char TouchBrowserFrameView::kViewClassName[] =
53 "browser/ui/touch/frame/TouchBrowserFrameView"; 189 "browser/ui/touch/frame/TouchBrowserFrameView";
54 190
55 /////////////////////////////////////////////////////////////////////////////// 191 ///////////////////////////////////////////////////////////////////////////////
56 // TouchBrowserFrameView, public: 192 // TouchBrowserFrameView, public:
57 193
58 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 194 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
59 BrowserView* browser_view) 195 BrowserView* browser_view)
60 : OpaqueBrowserFrameView(frame, browser_view), 196 : OpaqueBrowserFrameView(frame, browser_view),
61 keyboard_showing_(false), 197 keyboard_showing_(false),
62 keyboard_height_(kDefaultKeyboardHeight), 198 keyboard_height_(kDefaultKeyboardHeight),
63 focus_listener_added_(false), 199 focus_listener_added_(false),
64 keyboard_(NULL) { 200 keyboard_(NULL),
201 up_(sensors::ScreenOrientation::TOP) {
65 registrar_.Add(this, 202 registrar_.Add(this,
66 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 203 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
67 NotificationService::AllSources()); 204 NotificationService::AllSources());
68 registrar_.Add(this, 205 registrar_.Add(this,
69 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, 206 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
70 NotificationService::AllSources()); 207 NotificationService::AllSources());
71 registrar_.Add(this, 208 registrar_.Add(this,
72 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 209 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
73 NotificationService::AllSources()); 210 NotificationService::AllSources());
74 registrar_.Add(this, 211 registrar_.Add(this,
(...skipping 10 matching lines...) Expand all
85 222
86 animation_.reset(new ui::SlideAnimation(this)); 223 animation_.reset(new ui::SlideAnimation(this));
87 animation_->SetTweenType(ui::Tween::LINEAR); 224 animation_->SetTweenType(ui::Tween::LINEAR);
88 animation_->SetSlideDuration(kKeyboardSlideDuration); 225 animation_->SetSlideDuration(kKeyboardSlideDuration);
89 226
90 #if defined(OS_CHROMEOS) 227 #if defined(OS_CHROMEOS)
91 chromeos::input_method::InputMethodManager* manager = 228 chromeos::input_method::InputMethodManager* manager =
92 chromeos::input_method::InputMethodManager::GetInstance(); 229 chromeos::input_method::InputMethodManager::GetInstance();
93 manager->AddVirtualKeyboardObserver(this); 230 manager->AddVirtualKeyboardObserver(this);
94 #endif 231 #endif
232
233 sensors::Provider::GetInstance()->AddListener(this);
95 } 234 }
96 235
97 TouchBrowserFrameView::~TouchBrowserFrameView() { 236 TouchBrowserFrameView::~TouchBrowserFrameView() {
98 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 237 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
238 sensors::Provider::GetInstance()->RemoveListener(this);
99 } 239 }
100 240
101 std::string TouchBrowserFrameView::GetClassName() const { 241 std::string TouchBrowserFrameView::GetClassName() const {
102 return kViewClassName; 242 return kViewClassName;
103 } 243 }
104 244
105 void TouchBrowserFrameView::Layout() { 245 void TouchBrowserFrameView::Layout() {
106 OpaqueBrowserFrameView::Layout(); 246 OpaqueBrowserFrameView::Layout();
107 247
108 if (!keyboard_) 248 if (!keyboard_)
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 494 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
355 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( 495 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView(
356 host->routing_id())); 496 host->routing_id()));
357 } else { 497 } else {
358 // Notify the keyboard that it is hidden now. 498 // Notify the keyboard that it is hidden now.
359 keyboard_->SetVisible(false); 499 keyboard_->SetVisible(false);
360 } 500 }
361 SchedulePaint(); 501 SchedulePaint();
362 } 502 }
363 503
504 void TouchBrowserFrameView::OnScreenOrientationChange(
505 const sensors::ScreenOrientation& change) {
506
507 views::Widget* widget = GetWidget();
sadrul 2011/07/15 15:25:48 Please try this with --views-desktop and see if th
508 views::View* root = widget->GetRootView();
509 TouchBrowserFrameRotation::Perform(root, up_, change.upward);
510 up_ = change.upward;
511 }
512
364 #if defined(OS_CHROMEOS) 513 #if defined(OS_CHROMEOS)
365 void TouchBrowserFrameView::VirtualKeyboardChanged( 514 void TouchBrowserFrameView::VirtualKeyboardChanged(
366 chromeos::input_method::InputMethodManager* manager, 515 chromeos::input_method::InputMethodManager* manager,
367 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, 516 const chromeos::input_method::VirtualKeyboard& virtual_keyboard,
368 const std::string& virtual_keyboard_layout) { 517 const std::string& virtual_keyboard_layout) {
369 if (!keyboard_) 518 if (!keyboard_)
370 return; 519 return;
371 520
372 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); 521 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout);
373 keyboard_->LoadURL(url); 522 keyboard_->LoadURL(url);
374 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); 523 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec();
375 } 524 }
376 #endif 525 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698