OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/workspace/multi_window_resize_controller.h" | 5 #include "ash/wm/workspace/multi_window_resize_controller.h" |
6 | 6 |
7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
8 #include "ash/resources/grit/ash_resources.h" | |
9 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
10 #include "ash/wm/workspace/workspace_window_resizer.h" | 9 #include "ash/wm/workspace/workspace_window_resizer.h" |
11 #include "ash/wm_window.h" | 10 #include "ash/wm_window.h" |
12 #include "ui/base/cursor/cursor.h" | 11 #include "ui/base/cursor/cursor.h" |
13 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
14 #include "ui/base/resource/resource_bundle.h" | |
15 #include "ui/display/screen.h" | 13 #include "ui/display/screen.h" |
16 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
18 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
19 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
20 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
21 #include "ui/wm/core/compound_event_filter.h" | 19 #include "ui/wm/core/compound_event_filter.h" |
22 | 20 |
23 namespace ash { | 21 namespace ash { |
24 namespace { | 22 namespace { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 55 } |
58 | 56 |
59 } // namespace | 57 } // namespace |
60 | 58 |
61 // View contained in the widget. Passes along mouse events to the | 59 // View contained in the widget. Passes along mouse events to the |
62 // MultiWindowResizeController so that it can start/stop the resize loop. | 60 // MultiWindowResizeController so that it can start/stop the resize loop. |
63 class MultiWindowResizeController::ResizeView : public views::View { | 61 class MultiWindowResizeController::ResizeView : public views::View { |
64 public: | 62 public: |
65 explicit ResizeView(MultiWindowResizeController* controller, | 63 explicit ResizeView(MultiWindowResizeController* controller, |
66 Direction direction) | 64 Direction direction) |
67 : controller_(controller), direction_(direction), image_(NULL) { | 65 : controller_(controller), direction_(direction) {} |
68 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
69 int image_id = direction == TOP_BOTTOM ? IDR_AURA_MULTI_WINDOW_RESIZE_H | |
70 : IDR_AURA_MULTI_WINDOW_RESIZE_V; | |
71 image_ = rb.GetImageNamed(image_id).ToImageSkia(); | |
72 } | |
73 | 66 |
74 // views::View overrides: | 67 // views::View overrides: |
75 gfx::Size GetPreferredSize() const override { | 68 gfx::Size GetPreferredSize() const override { |
76 return gfx::Size(image_->width(), image_->height()); | 69 const bool vert = direction_ == LEFT_RIGHT; |
| 70 return gfx::Size(vert ? kShortSide : kLongSide, |
| 71 vert ? kLongSide : kShortSide); |
77 } | 72 } |
78 void OnPaint(gfx::Canvas* canvas) override { | 73 void OnPaint(gfx::Canvas* canvas) override { |
79 canvas->DrawImageInt(*image_, 0, 0); | 74 cc::PaintFlags flags; |
| 75 flags.setColor(SkColorSetA(SK_ColorBLACK, 0x7F)); |
| 76 flags.setAntiAlias(true); |
| 77 canvas->DrawRoundRect(gfx::RectF(GetLocalBounds()), 2, flags); |
| 78 |
| 79 // Craft the left arrow. |
| 80 const SkRect kArrowBounds = SkRect::MakeXYWH(4, 28, 4, 8); |
| 81 SkPath path; |
| 82 path.moveTo(kArrowBounds.right(), kArrowBounds.y()); |
| 83 path.lineTo(kArrowBounds.x(), kArrowBounds.centerY()); |
| 84 path.lineTo(kArrowBounds.right(), kArrowBounds.bottom()); |
| 85 path.close(); |
| 86 |
| 87 // Do the same for the right arrow. |
| 88 SkMatrix flip; |
| 89 flip.setScale(-1, 1, kShortSide / 2, kLongSide / 2); |
| 90 path.addPath(path, flip); |
| 91 |
| 92 // The arrows are drawn for the vertical orientation; rotate if need be. |
| 93 if (direction_ == TOP_BOTTOM) { |
| 94 SkMatrix transform; |
| 95 constexpr int kHalfShort = kShortSide / 2; |
| 96 constexpr int kHalfLong = kLongSide / 2; |
| 97 transform.setRotate(90, kHalfShort, kHalfLong); |
| 98 transform.postTranslate(kHalfLong - kHalfShort, kHalfShort - kHalfLong); |
| 99 path.transform(transform); |
| 100 } |
| 101 |
| 102 flags.setColor(SK_ColorWHITE); |
| 103 canvas->DrawPath(path, flags); |
80 } | 104 } |
| 105 |
81 bool OnMousePressed(const ui::MouseEvent& event) override { | 106 bool OnMousePressed(const ui::MouseEvent& event) override { |
82 gfx::Point location(event.location()); | 107 gfx::Point location(event.location()); |
83 views::View::ConvertPointToScreen(this, &location); | 108 views::View::ConvertPointToScreen(this, &location); |
84 controller_->StartResize(location); | 109 controller_->StartResize(location); |
85 return true; | 110 return true; |
86 } | 111 } |
| 112 |
87 bool OnMouseDragged(const ui::MouseEvent& event) override { | 113 bool OnMouseDragged(const ui::MouseEvent& event) override { |
88 gfx::Point location(event.location()); | 114 gfx::Point location(event.location()); |
89 views::View::ConvertPointToScreen(this, &location); | 115 views::View::ConvertPointToScreen(this, &location); |
90 controller_->Resize(location, event.flags()); | 116 controller_->Resize(location, event.flags()); |
91 return true; | 117 return true; |
92 } | 118 } |
| 119 |
93 void OnMouseReleased(const ui::MouseEvent& event) override { | 120 void OnMouseReleased(const ui::MouseEvent& event) override { |
94 controller_->CompleteResize(); | 121 controller_->CompleteResize(); |
95 } | 122 } |
| 123 |
96 void OnMouseCaptureLost() override { controller_->CancelResize(); } | 124 void OnMouseCaptureLost() override { controller_->CancelResize(); } |
| 125 |
97 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override { | 126 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override { |
98 int component = (direction_ == LEFT_RIGHT) ? HTRIGHT : HTBOTTOM; | 127 int component = (direction_ == LEFT_RIGHT) ? HTRIGHT : HTBOTTOM; |
99 return ::wm::CompoundEventFilter::CursorForWindowComponent(component); | 128 return ::wm::CompoundEventFilter::CursorForWindowComponent(component); |
100 } | 129 } |
101 | 130 |
102 private: | 131 private: |
| 132 static constexpr int kLongSide = 64; |
| 133 static constexpr int kShortSide = 28; |
| 134 |
103 MultiWindowResizeController* controller_; | 135 MultiWindowResizeController* controller_; |
104 const Direction direction_; | 136 const Direction direction_; |
105 const gfx::ImageSkia* image_; | |
106 | 137 |
107 DISALLOW_COPY_AND_ASSIGN(ResizeView); | 138 DISALLOW_COPY_AND_ASSIGN(ResizeView); |
108 }; | 139 }; |
109 | 140 |
110 // MouseWatcherHost implementation for MultiWindowResizeController. Forwards | 141 // MouseWatcherHost implementation for MultiWindowResizeController. Forwards |
111 // Contains() to MultiWindowResizeController. | 142 // Contains() to MultiWindowResizeController. |
112 class MultiWindowResizeController::ResizeMouseWatcherHost | 143 class MultiWindowResizeController::ResizeMouseWatcherHost |
113 : public views::MouseWatcherHost { | 144 : public views::MouseWatcherHost { |
114 public: | 145 public: |
115 ResizeMouseWatcherHost(MultiWindowResizeController* host) : host_(host) {} | 146 ResizeMouseWatcherHost(MultiWindowResizeController* host) : host_(host) {} |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 562 |
532 bool MultiWindowResizeController::IsOverComponent( | 563 bool MultiWindowResizeController::IsOverComponent( |
533 WmWindow* window, | 564 WmWindow* window, |
534 const gfx::Point& location_in_screen, | 565 const gfx::Point& location_in_screen, |
535 int component) const { | 566 int component) const { |
536 gfx::Point window_loc = window->ConvertPointFromScreen(location_in_screen); | 567 gfx::Point window_loc = window->ConvertPointFromScreen(location_in_screen); |
537 return window->GetNonClientComponent(window_loc) == component; | 568 return window->GetNonClientComponent(window_loc) == component; |
538 } | 569 } |
539 | 570 |
540 } // namespace ash | 571 } // namespace ash |
OLD | NEW |