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