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/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, |
60 BrowserView* browser_view) | 93 BrowserView* browser_view) |
61 : OpaqueBrowserFrameView(frame, browser_view), | 94 : OpaqueBrowserFrameView(frame, browser_view), |
62 keyboard_showing_(false), | 95 keyboard_showing_(false), |
63 keyboard_height_(kDefaultKeyboardHeight), | 96 keyboard_height_(kDefaultKeyboardHeight), |
64 focus_listener_added_(false), | 97 focus_listener_added_(false), |
| 98 initialized_screen_rotation_(false), |
65 keyboard_(NULL) { | 99 keyboard_(NULL) { |
66 registrar_.Add(this, | 100 registrar_.Add(this, |
67 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 101 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
68 NotificationService::AllSources()); | 102 NotificationService::AllSources()); |
69 registrar_.Add(this, | 103 registrar_.Add(this, |
70 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 104 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
71 NotificationService::AllSources()); | 105 NotificationService::AllSources()); |
72 registrar_.Add(this, | 106 registrar_.Add(this, |
73 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 107 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
74 NotificationService::AllSources()); | 108 NotificationService::AllSources()); |
(...skipping 11 matching lines...) Expand all Loading... |
86 | 120 |
87 animation_.reset(new ui::SlideAnimation(this)); | 121 animation_.reset(new ui::SlideAnimation(this)); |
88 animation_->SetTweenType(ui::Tween::LINEAR); | 122 animation_->SetTweenType(ui::Tween::LINEAR); |
89 animation_->SetSlideDuration(kKeyboardSlideDuration); | 123 animation_->SetSlideDuration(kKeyboardSlideDuration); |
90 | 124 |
91 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
92 chromeos::input_method::InputMethodManager* manager = | 126 chromeos::input_method::InputMethodManager* manager = |
93 chromeos::input_method::InputMethodManager::GetInstance(); | 127 chromeos::input_method::InputMethodManager::GetInstance(); |
94 manager->AddVirtualKeyboardObserver(this); | 128 manager->AddVirtualKeyboardObserver(this); |
95 #endif | 129 #endif |
| 130 |
| 131 sensors::Provider::GetInstance()->AddListener(this); |
96 } | 132 } |
97 | 133 |
98 TouchBrowserFrameView::~TouchBrowserFrameView() { | 134 TouchBrowserFrameView::~TouchBrowserFrameView() { |
99 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); | 135 browser_view()->browser()->tabstrip_model()->RemoveObserver(this); |
| 136 sensors::Provider::GetInstance()->RemoveListener(this); |
100 } | 137 } |
101 | 138 |
102 int TouchBrowserFrameView::NonClientHitTest(const gfx::Point& point) { | 139 int TouchBrowserFrameView::NonClientHitTest(const gfx::Point& point) { |
103 if (keyboard_->GetMirroredBounds().Contains(point)) | 140 if (keyboard_->GetMirroredBounds().Contains(point)) |
104 return HTCLIENT; | 141 return HTCLIENT; |
105 return OpaqueBrowserFrameView::NonClientHitTest(point); | 142 return OpaqueBrowserFrameView::NonClientHitTest(point); |
106 } | 143 } |
107 | 144 |
108 std::string TouchBrowserFrameView::GetClassName() const { | 145 std::string TouchBrowserFrameView::GetClassName() const { |
109 return kViewClassName; | 146 return kViewClassName; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); | 399 browser_view()->browser()->GetSelectedTabContents()->render_view_host(); |
363 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( | 400 host->Send(new ViewMsg_ScrollFocusedEditableNodeIntoView( |
364 host->routing_id())); | 401 host->routing_id())); |
365 } else { | 402 } else { |
366 // Notify the keyboard that it is hidden now. | 403 // Notify the keyboard that it is hidden now. |
367 keyboard_->SetVisible(false); | 404 keyboard_->SetVisible(false); |
368 } | 405 } |
369 SchedulePaint(); | 406 SchedulePaint(); |
370 } | 407 } |
371 | 408 |
| 409 void TouchBrowserFrameView::OnScreenOrientationChanged( |
| 410 const sensors::ScreenOrientation& change) { |
| 411 // In views desktop mode, then the desktop_window_view will not be NULL and |
| 412 // is the view to be rotated. |
| 413 views::View* to_rotate = |
| 414 views::desktop::DesktopWindowView::desktop_window_view; |
| 415 |
| 416 if (!to_rotate) { |
| 417 // Otherwise, rotate the widget's view. |
| 418 views::Widget* widget = GetWidget(); |
| 419 to_rotate = widget->GetRootView(); |
| 420 } |
| 421 |
| 422 if (!initialized_screen_rotation_) { |
| 423 to_rotate->SetPaintToLayer(true); |
| 424 to_rotate->SetLayerPropertySetter( |
| 425 ScreenRotationSetterFactory::Create(to_rotate)); |
| 426 initialized_screen_rotation_ = true; |
| 427 } |
| 428 |
| 429 ui::Transform xform = SideToTransform(change.upward, |
| 430 to_rotate->GetTransform(), |
| 431 to_rotate->size()); |
| 432 to_rotate->SetTransform(xform); |
| 433 } |
| 434 |
372 #if defined(OS_CHROMEOS) | 435 #if defined(OS_CHROMEOS) |
373 void TouchBrowserFrameView::VirtualKeyboardChanged( | 436 void TouchBrowserFrameView::VirtualKeyboardChanged( |
374 chromeos::input_method::InputMethodManager* manager, | 437 chromeos::input_method::InputMethodManager* manager, |
375 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, | 438 const chromeos::input_method::VirtualKeyboard& virtual_keyboard, |
376 const std::string& virtual_keyboard_layout) { | 439 const std::string& virtual_keyboard_layout) { |
377 const GURL& new_url = | 440 const GURL& new_url = |
378 virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); | 441 virtual_keyboard.GetURLForLayout(virtual_keyboard_layout); |
379 if (new_url == url_) | 442 if (new_url == url_) |
380 return; | 443 return; |
381 | 444 |
382 url_ = new_url; | 445 url_ = new_url; |
383 if (keyboard_) | 446 if (keyboard_) |
384 keyboard_->LoadURL(url_); | 447 keyboard_->LoadURL(url_); |
385 // |keyboard_| can be NULL here. In that case, the |url_| will be used in | 448 // |keyboard_| can be NULL here. In that case, the |url_| will be used in |
386 // InitVirtualKeyboard() later. | 449 // InitVirtualKeyboard() later. |
387 } | 450 } |
388 #endif | 451 #endif |
OLD | NEW |