| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/frame/frame_border_hit_test_controller.h" | 5 #include "ash/frame/frame_border_hit_test_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/ash_constants.h" | 9 #include "ash/common/ash_constants.h" |
| 10 #include "ash/common/wm/window_state_observer.h" | 10 #include "ash/common/wm/window_state_observer.h" |
| 11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 12 #include "ash/wm/resize_handle_window_targeter.h" | 12 #include "ash/wm/resize_handle_window_targeter.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
| 16 #include "ui/aura/window_targeter.h" | 16 #include "ui/aura/window_targeter.h" |
| 17 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/widget/widget_delegate.h" | 19 #include "ui/views/widget/widget_delegate.h" |
| 20 #include "ui/views/window/non_client_view.h" | 20 #include "ui/views/window/non_client_view.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 | 23 |
| 24 FrameBorderHitTestController::FrameBorderHitTestController(views::Widget* frame) | 24 FrameBorderHitTestController::FrameBorderHitTestController(views::Widget* frame) |
| 25 : frame_window_(frame->GetNativeWindow()) { | 25 : frame_window_(frame->GetNativeWindow()) { |
| 26 frame_window_->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( | 26 frame_window_->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
| 27 new ResizeHandleWindowTargeter(frame_window_, NULL))); | 27 new ResizeHandleWindowTargeter(frame_window_, NULL))); |
| 28 } | 28 } |
| 29 | 29 |
| 30 FrameBorderHitTestController::~FrameBorderHitTestController() { | 30 FrameBorderHitTestController::~FrameBorderHitTestController() {} |
| 31 } | |
| 32 | 31 |
| 33 // static | 32 // static |
| 34 int FrameBorderHitTestController::NonClientHitTest( | 33 int FrameBorderHitTestController::NonClientHitTest( |
| 35 views::NonClientFrameView* view, | 34 views::NonClientFrameView* view, |
| 36 FrameCaptionButtonContainerView* caption_button_container, | 35 FrameCaptionButtonContainerView* caption_button_container, |
| 37 const gfx::Point& point_in_widget) { | 36 const gfx::Point& point_in_widget) { |
| 38 gfx::Rect expanded_bounds = view->bounds(); | 37 gfx::Rect expanded_bounds = view->bounds(); |
| 39 int outside_bounds = kResizeOutsideBoundsSize; | 38 int outside_bounds = kResizeOutsideBoundsSize; |
| 40 | 39 |
| 41 if (aura::Env::GetInstance()->is_touch_down()) | 40 if (aura::Env::GetInstance()->is_touch_down()) |
| 42 outside_bounds *= kResizeOutsideBoundsScaleForTouch; | 41 outside_bounds *= kResizeOutsideBoundsScaleForTouch; |
| 43 expanded_bounds.Inset(-outside_bounds, -outside_bounds); | 42 expanded_bounds.Inset(-outside_bounds, -outside_bounds); |
| 44 | 43 |
| 45 if (!expanded_bounds.Contains(point_in_widget)) | 44 if (!expanded_bounds.Contains(point_in_widget)) |
| 46 return HTNOWHERE; | 45 return HTNOWHERE; |
| 47 | 46 |
| 48 // Check the frame first, as we allow a small area overlapping the contents | 47 // Check the frame first, as we allow a small area overlapping the contents |
| 49 // to be used for resize handles. | 48 // to be used for resize handles. |
| 50 views::Widget* frame = view->GetWidget(); | 49 views::Widget* frame = view->GetWidget(); |
| 51 bool can_ever_resize = frame->widget_delegate()->CanResize(); | 50 bool can_ever_resize = frame->widget_delegate()->CanResize(); |
| 52 // Don't allow overlapping resize handles when the window is maximized or | 51 // Don't allow overlapping resize handles when the window is maximized or |
| 53 // fullscreen, as it can't be resized in those states. | 52 // fullscreen, as it can't be resized in those states. |
| 54 int resize_border = kResizeInsideBoundsSize; | 53 int resize_border = kResizeInsideBoundsSize; |
| 55 if (frame->IsMaximized() || frame->IsFullscreen()) { | 54 if (frame->IsMaximized() || frame->IsFullscreen()) { |
| 56 resize_border = 0; | 55 resize_border = 0; |
| 57 can_ever_resize = false; | 56 can_ever_resize = false; |
| 58 } | 57 } |
| 59 int frame_component = view->GetHTComponentForFrame(point_in_widget, | 58 int frame_component = view->GetHTComponentForFrame( |
| 60 resize_border, | 59 point_in_widget, resize_border, resize_border, kResizeAreaCornerSize, |
| 61 resize_border, | 60 kResizeAreaCornerSize, can_ever_resize); |
| 62 kResizeAreaCornerSize, | |
| 63 kResizeAreaCornerSize, | |
| 64 can_ever_resize); | |
| 65 if (frame_component != HTNOWHERE) | 61 if (frame_component != HTNOWHERE) |
| 66 return frame_component; | 62 return frame_component; |
| 67 | 63 |
| 68 int client_component = frame->client_view()->NonClientHitTest( | 64 int client_component = |
| 69 point_in_widget); | 65 frame->client_view()->NonClientHitTest(point_in_widget); |
| 70 if (client_component != HTNOWHERE) | 66 if (client_component != HTNOWHERE) |
| 71 return client_component; | 67 return client_component; |
| 72 | 68 |
| 73 if (caption_button_container->visible()) { | 69 if (caption_button_container->visible()) { |
| 74 gfx::Point point_in_caption_button_container(point_in_widget); | 70 gfx::Point point_in_caption_button_container(point_in_widget); |
| 75 views::View::ConvertPointFromWidget(caption_button_container, | 71 views::View::ConvertPointFromWidget(caption_button_container, |
| 76 &point_in_caption_button_container); | 72 &point_in_caption_button_container); |
| 77 int caption_button_component = caption_button_container->NonClientHitTest( | 73 int caption_button_component = caption_button_container->NonClientHitTest( |
| 78 point_in_caption_button_container); | 74 point_in_caption_button_container); |
| 79 if (caption_button_component != HTNOWHERE) | 75 if (caption_button_component != HTNOWHERE) |
| 80 return caption_button_component; | 76 return caption_button_component; |
| 81 } | 77 } |
| 82 | 78 |
| 83 // Caption is a safe default. | 79 // Caption is a safe default. |
| 84 return HTCAPTION; | 80 return HTCAPTION; |
| 85 } | 81 } |
| 86 | 82 |
| 87 } // namespace ash | 83 } // namespace ash |
| OLD | NEW |