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 "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) { | |
52 switch (side) { | |
53 case sensors::ScreenOrientation::RIGHT: return 90; | |
54 case sensors::ScreenOrientation::LEFT: return -90; | |
55 case sensors::ScreenOrientation::BOTTOM: return 180; | |
56 default: return 0; | |
57 } | |
58 } | |
59 | |
49 } // namespace | 60 } // namespace |
50 | 61 |
51 // static | 62 // static |
52 const char TouchBrowserFrameView::kViewClassName[] = | 63 const char TouchBrowserFrameView::kViewClassName[] = |
53 "browser/ui/touch/frame/TouchBrowserFrameView"; | 64 "browser/ui/touch/frame/TouchBrowserFrameView"; |
54 | 65 |
55 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
56 // TouchBrowserFrameView, public: | 67 // TouchBrowserFrameView, public: |
57 | 68 |
58 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 69 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
59 BrowserView* browser_view) | 70 BrowserView* browser_view) |
60 : OpaqueBrowserFrameView(frame, browser_view), | 71 : OpaqueBrowserFrameView(frame, browser_view), |
61 keyboard_showing_(false), | 72 keyboard_showing_(false), |
62 keyboard_height_(kDefaultKeyboardHeight), | 73 keyboard_height_(kDefaultKeyboardHeight), |
63 focus_listener_added_(false), | 74 focus_listener_added_(false), |
64 keyboard_(NULL) { | 75 keyboard_(NULL), |
76 up_(sensors::ScreenOrientation::TOP) { | |
65 registrar_.Add(this, | 77 registrar_.Add(this, |
66 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 78 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
67 NotificationService::AllSources()); | 79 NotificationService::AllSources()); |
68 registrar_.Add(this, | 80 registrar_.Add(this, |
69 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 81 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
70 NotificationService::AllSources()); | 82 NotificationService::AllSources()); |
71 registrar_.Add(this, | 83 registrar_.Add(this, |
72 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 84 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
73 NotificationService::AllSources()); | 85 NotificationService::AllSources()); |
74 registrar_.Add(this, | 86 registrar_.Add(this, |
(...skipping 10 matching lines...) Expand all Loading... | |
85 | 97 |
86 animation_.reset(new ui::SlideAnimation(this)); | 98 animation_.reset(new ui::SlideAnimation(this)); |
87 animation_->SetTweenType(ui::Tween::LINEAR); | 99 animation_->SetTweenType(ui::Tween::LINEAR); |
88 animation_->SetSlideDuration(kKeyboardSlideDuration); | 100 animation_->SetSlideDuration(kKeyboardSlideDuration); |
89 | 101 |
90 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
91 chromeos::input_method::InputMethodManager* manager = | 103 chromeos::input_method::InputMethodManager* manager = |
92 chromeos::input_method::InputMethodManager::GetInstance(); | 104 chromeos::input_method::InputMethodManager::GetInstance(); |
93 manager->AddVirtualKeyboardObserver(this); | 105 manager->AddVirtualKeyboardObserver(this); |
94 #endif | 106 #endif |
107 | |
108 sensors::Provider::GetInstance()->AddListener(this); | |
95 } | 109 } |
96 | 110 |
97 TouchBrowserFrameView::~TouchBrowserFrameView() { | 111 TouchBrowserFrameView::~TouchBrowserFrameView() { |
98 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | 112 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); |
113 sensors::Provider::GetInstance()->RemoveListener(this); | |
99 } | 114 } |
100 | 115 |
101 std::string TouchBrowserFrameView::GetClassName() const { | 116 std::string TouchBrowserFrameView::GetClassName() const { |
102 return kViewClassName; | 117 return kViewClassName; |
103 } | 118 } |
104 | 119 |
105 void TouchBrowserFrameView::Layout() { | 120 void TouchBrowserFrameView::Layout() { |
106 OpaqueBrowserFrameView::Layout(); | 121 OpaqueBrowserFrameView::Layout(); |
107 | 122 |
108 if (!keyboard_) | 123 if (!keyboard_) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); | 369 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); |
355 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( | 370 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( |
356 host->routing_id())); | 371 host->routing_id())); |
357 } else { | 372 } else { |
358 // Notify the keyboard that it is hidden now. | 373 // Notify the keyboard that it is hidden now. |
359 keyboard_->SetVisible(false); | 374 keyboard_->SetVisible(false); |
360 } | 375 } |
361 SchedulePaint(); | 376 SchedulePaint(); |
362 } | 377 } |
363 | 378 |
379 void TouchBrowserFrameView::OnScreenOrientationChanged( | |
380 const sensors::ScreenOrientation& change) { | |
381 | |
382 views::View* to_rotate = | |
383 views::desktop::DesktopWindowView::desktop_window_view; | |
384 | |
385 if (!to_rotate) { | |
386 views::Widget* widget = GetWidget(); | |
387 to_rotate = widget->GetRootView(); | |
388 } | |
389 | |
390 views::ScreenRotation::Perform( | |
391 to_rotate, | |
392 SideToDegrees(up_), | |
393 SideToDegrees(change.upward)); | |
cwolfe
2011/07/21 17:47:01
ScreenOrientation::FRONT and ::BACK should probabl
| |
394 | |
395 up_ = change.upward; | |
396 } | |
397 | |
364 #if defined(OS_CHROMEOS) | 398 #if defined(OS_CHROMEOS) |
365 void TouchBrowserFrameView::VirtualKeyboardChanged( | 399 void TouchBrowserFrameView::VirtualKeyboardChanged( |
366 chromeos::input_method::InputMethodManager* manager, | 400 chromeos::input_method::InputMethodManager* manager, |
367 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 401 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
368 const std::string& virtual_keyboard_layout) { | 402 const std::string& virtual_keyboard_layout) { |
369 if (!keyboard_) | 403 if (!keyboard_) |
370 return; | 404 return; |
371 | 405 |
372 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 406 const GURL& url = virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
373 keyboard_->LoadURL(url); | 407 keyboard_->LoadURL(url); |
374 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); | 408 VLOG(1) << "VirtualKeyboardChanged: Switched to " << url.spec(); |
375 } | 409 } |
376 #endif | 410 #endif |
OLD | NEW |