| 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/ui/touch/animation/screen_rotation_setter.h" | |
| 8 #include "views/controls/button/image_button.h" | 7 #include "views/controls/button/image_button.h" |
| 9 #include "views/desktop/desktop_window_view.h" | 8 #include "views/desktop/desktop_window_view.h" |
| 10 #include "ui/gfx/transform.h" | 9 #include "ui/gfx/compositor/layer.h" |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 ui::Transform SideToTransform(sensors::ScreenOrientation::Side side, | |
| 15 const ui::Transform& old_transform, | |
| 16 const gfx::Size& size) { | |
| 17 gfx::Point origin; | |
| 18 gfx::Point bottom_right(size.width(), size.height()); | |
| 19 old_transform.TransformPoint(origin); | |
| 20 old_transform.TransformPoint(bottom_right); | |
| 21 int original_width = abs(origin.x() - bottom_right.x()); | |
| 22 int original_height = abs(origin.y() - bottom_right.y()); | |
| 23 ui::Transform to_return; | |
| 24 switch (side) { | |
| 25 case sensors::ScreenOrientation::TOP: break; | |
| 26 case sensors::ScreenOrientation::RIGHT: | |
| 27 to_return.ConcatRotate(90); | |
| 28 to_return.ConcatTranslate(original_width, 0); | |
| 29 break; | |
| 30 case sensors::ScreenOrientation::LEFT: | |
| 31 to_return.ConcatRotate(-90); | |
| 32 to_return.ConcatTranslate(0, original_height); | |
| 33 break; | |
| 34 case sensors::ScreenOrientation::BOTTOM: | |
| 35 to_return.ConcatRotate(180); | |
| 36 to_return.ConcatTranslate(original_width, original_height); | |
| 37 break; | |
| 38 default: | |
| 39 to_return = old_transform; | |
| 40 break; | |
| 41 } | |
| 42 return to_return; | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | 10 |
| 47 // static | 11 // static |
| 48 const char TouchBrowserFrameView::kViewClassName[] = | 12 const char TouchBrowserFrameView::kViewClassName[] = |
| 49 "browser/ui/touch/frame/TouchBrowserFrameView"; | 13 "browser/ui/touch/frame/TouchBrowserFrameView"; |
| 50 | 14 |
| 51 /////////////////////////////////////////////////////////////////////////////// | 15 /////////////////////////////////////////////////////////////////////////////// |
| 52 // TouchBrowserFrameView, public: | 16 // TouchBrowserFrameView, public: |
| 53 | 17 |
| 54 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | 18 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, |
| 55 BrowserView* browser_view) | 19 BrowserView* browser_view) |
| 56 : OpaqueBrowserFrameView(frame, browser_view), | 20 : OpaqueBrowserFrameView(frame, browser_view), |
| 57 initialized_screen_rotation_(false) { | 21 initialized_screen_rotation_(false) { |
| 58 sensors::Provider::GetInstance()->AddListener(this); | |
| 59 } | 22 } |
| 60 | 23 |
| 61 TouchBrowserFrameView::~TouchBrowserFrameView() { | 24 TouchBrowserFrameView::~TouchBrowserFrameView() { |
| 62 sensors::Provider::GetInstance()->RemoveListener(this); | |
| 63 } | 25 } |
| 64 | 26 |
| 65 std::string TouchBrowserFrameView::GetClassName() const { | 27 std::string TouchBrowserFrameView::GetClassName() const { |
| 66 return kViewClassName; | 28 return kViewClassName; |
| 67 } | 29 } |
| 68 | 30 |
| 69 bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const { | 31 bool TouchBrowserFrameView::HitTest(const gfx::Point& point) const { |
| 70 if (OpaqueBrowserFrameView::HitTest(point)) | 32 if (OpaqueBrowserFrameView::HitTest(point)) |
| 71 return true; | 33 return true; |
| 72 | 34 |
| 73 if (close_button()->IsVisible() && | 35 if (close_button()->IsVisible() && |
| 74 close_button()->GetMirroredBounds().Contains(point)) | 36 close_button()->GetMirroredBounds().Contains(point)) |
| 75 return true; | 37 return true; |
| 76 if (restore_button()->IsVisible() && | 38 if (restore_button()->IsVisible() && |
| 77 restore_button()->GetMirroredBounds().Contains(point)) | 39 restore_button()->GetMirroredBounds().Contains(point)) |
| 78 return true; | 40 return true; |
| 79 if (maximize_button()->IsVisible() && | 41 if (maximize_button()->IsVisible() && |
| 80 maximize_button()->GetMirroredBounds().Contains(point)) | 42 maximize_button()->GetMirroredBounds().Contains(point)) |
| 81 return true; | 43 return true; |
| 82 if (minimize_button()->IsVisible() && | 44 if (minimize_button()->IsVisible() && |
| 83 minimize_button()->GetMirroredBounds().Contains(point)) | 45 minimize_button()->GetMirroredBounds().Contains(point)) |
| 84 return true; | 46 return true; |
| 85 | 47 |
| 86 return false; | 48 return false; |
| 87 } | 49 } |
| 88 | |
| 89 void TouchBrowserFrameView::OnScreenOrientationChanged( | |
| 90 const sensors::ScreenOrientation& change) { | |
| 91 // In views desktop mode, then the desktop_window_view will not be NULL and | |
| 92 // is the view to be rotated. | |
| 93 views::View* to_rotate = | |
| 94 views::desktop::DesktopWindowView::desktop_window_view; | |
| 95 | |
| 96 if (!to_rotate) { | |
| 97 // Otherwise, rotate the widget's view. | |
| 98 views::Widget* widget = GetWidget(); | |
| 99 to_rotate = widget->GetRootView(); | |
| 100 } | |
| 101 | |
| 102 if (!initialized_screen_rotation_) { | |
| 103 to_rotate->SetPaintToLayer(true); | |
| 104 to_rotate->SetLayerPropertySetter( | |
| 105 ScreenRotationSetterFactory::Create(to_rotate)); | |
| 106 initialized_screen_rotation_ = true; | |
| 107 } | |
| 108 | |
| 109 const ui::Transform& old_xform = to_rotate->GetTransform(); | |
| 110 const ui::Transform& new_xform = SideToTransform(change.upward, | |
| 111 old_xform, | |
| 112 to_rotate->size()); | |
| 113 if (old_xform != new_xform) | |
| 114 to_rotate->SetTransform(new_xform); | |
| 115 } | |
| OLD | NEW |