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

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: Removed unnecessary include 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/frame/keyboard_container_view.h" 12 #include "chrome/browser/ui/touch/frame/keyboard_container_view.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h" 14 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
15 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
16 #include "content/browser/renderer_host/render_view_host.h" 16 #include "content/browser/renderer_host/render_view_host.h"
17 #include "content/browser/tab_contents/navigation_controller.h" 17 #include "content/browser/tab_contents/navigation_controller.h"
18 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/browser/tab_contents/tab_contents_view.h" 19 #include "content/browser/tab_contents/tab_contents_view.h"
20 #include "content/common/content_notification_types.h" 20 #include "content/common/content_notification_types.h"
21 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
22 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
23 #include "ui/base/animation/slide_animation.h" 23 #include "ui/base/animation/slide_animation.h"
24 #include "ui/gfx/rect.h" 24 #include "ui/gfx/rect.h"
25 #include "ui/gfx/transform.h" 25 #include "ui/gfx/transform.h"
26 #include "views/animation/screen_rotation.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 31
30 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h" 33 #include "chrome/browser/chromeos/input_method/virtual_keyboard_selector.h"
32 #endif 34 #endif
33 35
34 namespace { 36 namespace {
35 37
36 const int kDefaultKeyboardHeight = 300; 38 const int kDefaultKeyboardHeight = 300;
37 const int kKeyboardSlideDuration = 300; // In milliseconds 39 const int kKeyboardSlideDuration = 300; // In milliseconds
38 40
39 PropertyAccessor<bool>* GetFocusedStateAccessor() { 41 PropertyAccessor<bool>* GetFocusedStateAccessor() {
40 static PropertyAccessor<bool> state; 42 static PropertyAccessor<bool> state;
41 return &state; 43 return &state;
42 } 44 }
43 45
44 bool TabContentsHasFocus(const TabContents* contents) { 46 bool TabContentsHasFocus(const TabContents* contents) {
45 views::View* view = static_cast<TabContentsViewTouch*>(contents->view()); 47 views::View* view = static_cast<TabContentsViewTouch*>(contents->view());
46 return view->Contains(view->GetFocusManager()->GetFocusedView()); 48 return view->Contains(view->GetFocusManager()->GetFocusedView());
47 } 49 }
48 50
51 int SideToDegrees(sensors::ScreenOrientation::Side side, int old_degrees) {
52 switch (side) {
53 case sensors::ScreenOrientation::TOP: return 0;
54 case sensors::ScreenOrientation::RIGHT: return 90;
55 case sensors::ScreenOrientation::LEFT: return -90;
56 case sensors::ScreenOrientation::BOTTOM: return 180;
57 default: return old_degrees;
58 }
59 }
60
49 } // namespace 61 } // namespace
50 62
51 // static 63 // static
52 const char TouchBrowserFrameView::kViewClassName[] = 64 const char TouchBrowserFrameView::kViewClassName[] =
53 "browser/ui/touch/frame/TouchBrowserFrameView"; 65 "browser/ui/touch/frame/TouchBrowserFrameView";
54 66
55 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
56 // TouchBrowserFrameView, public: 68 // TouchBrowserFrameView, public:
57 69
58 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, 70 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
59 BrowserView* browser_view) 71 BrowserView* browser_view)
60 : OpaqueBrowserFrameView(frame, browser_view), 72 : OpaqueBrowserFrameView(frame, browser_view),
61 keyboard_showing_(false), 73 keyboard_showing_(false),
62 keyboard_height_(kDefaultKeyboardHeight), 74 keyboard_height_(kDefaultKeyboardHeight),
63 focus_listener_added_(false), 75 focus_listener_added_(false),
64 keyboard_(NULL) { 76 keyboard_(NULL),
77 degrees_(0) {
65 registrar_.Add(this, 78 registrar_.Add(this,
66 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 79 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
67 NotificationService::AllSources()); 80 NotificationService::AllSources());
68 registrar_.Add(this, 81 registrar_.Add(this,
69 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, 82 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
70 NotificationService::AllSources()); 83 NotificationService::AllSources());
71 registrar_.Add(this, 84 registrar_.Add(this,
72 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 85 content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
73 NotificationService::AllSources()); 86 NotificationService::AllSources());
74 registrar_.Add(this, 87 registrar_.Add(this,
(...skipping 10 matching lines...) Expand all
85 98
86 animation_.reset(new ui::SlideAnimation(this)); 99 animation_.reset(new ui::SlideAnimation(this));
87 animation_->SetTweenType(ui::Tween::LINEAR); 100 animation_->SetTweenType(ui::Tween::LINEAR);
88 animation_->SetSlideDuration(kKeyboardSlideDuration); 101 animation_->SetSlideDuration(kKeyboardSlideDuration);
89 102
90 #if defined(OS_CHROMEOS) 103 #if defined(OS_CHROMEOS)
91 chromeos::input_method::InputMethodManager* manager = 104 chromeos::input_method::InputMethodManager* manager =
92 chromeos::input_method::InputMethodManager::GetInstance(); 105 chromeos::input_method::InputMethodManager::GetInstance();
93 manager->AddVirtualKeyboardObserver(this); 106 manager->AddVirtualKeyboardObserver(this);
94 #endif 107 #endif
108
109 sensors::Provider::GetInstance()->AddListener(this);
95 } 110 }
96 111
97 TouchBrowserFrameView::~TouchBrowserFrameView() { 112 TouchBrowserFrameView::~TouchBrowserFrameView() {
98 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); 113 browser_view()->browser()->tabstrip_model()->RemoveObserver(this);
114 sensors::Provider::GetInstance()->RemoveListener(this);
99 } 115 }
100 116
101 std::string TouchBrowserFrameView::GetClassName() const { 117 std::string TouchBrowserFrameView::GetClassName() const {
102 return kViewClassName; 118 return kViewClassName;
103 } 119 }
104 120
105 void TouchBrowserFrameView::Layout() { 121 void TouchBrowserFrameView::Layout() {
106 OpaqueBrowserFrameView::Layout(); 122 OpaqueBrowserFrameView::Layout();
107 123
108 if (!keyboard_) 124 if (!keyboard_)
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); 370 browser_view()->browser()->GetSelectedTabContents()->render_view_host();
355 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( 371 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView(
356 host->routing_id())); 372 host->routing_id()));
357 } else { 373 } else {
358 // Notify the keyboard that it is hidden now. 374 // Notify the keyboard that it is hidden now.
359 keyboard_->SetVisible(false); 375 keyboard_->SetVisible(false);
360 } 376 }
361 SchedulePaint(); 377 SchedulePaint();
362 } 378 }
363 379
380 void TouchBrowserFrameView::OnScreenOrientationChanged(
381 const sensors::ScreenOrientation& change) {
382
sky 2011/08/17 16:39:42 nit: remove this line.
383 views::View* to_rotate =
384 views::desktop::DesktopWindowView::desktop_window_view;
385
386 if (!to_rotate) {
387 views::Widget* widget = GetWidget();
388 to_rotate = widget->GetRootView();
389 }
390
391 int new_degrees = SideToDegrees(change.upward, degrees_);
392
393 to_rotate->EnqueueAnimation(new views::ScreenRotation(to_rotate,
sky 2011/08/17 16:39:42 Where is EnqueueAnimation defined?
394 degrees_,
395 new_degrees));
396 degrees_ = new_degrees;
397 }
398
364 #if defined(OS_CHROMEOS) 399 #if defined(OS_CHROMEOS)
365 void TouchBrowserFrameView::VirtualKeyboardChanged( 400 void TouchBrowserFrameView::VirtualKeyboardChanged(
366 chromeos::input_method::InputMethodManager* manager, 401 chromeos::input_method::InputMethodManager* manager,
367 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, 402 const chromeos::input_method::VirtualKeyboard& virtual_keyboard,
368 const std::string& virtual_keyboard_layout) { 403 const std::string& virtual_keyboard_layout) {
369 if (!keyboard_) 404 if (!keyboard_)
370 return; 405 return;
371 406
372 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); 407 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout);
373 keyboard_->LoadURL(url); 408 keyboard_->LoadURL(url);
374 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); 409 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec();
375 } 410 }
376 #endif 411 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698