Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ash/wm/workspace/multi_window_resize_controller.cc

Issue 2836493002: Draw multi window resize controls programmatically (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/resources/default_200_percent/common/multi_window_resize_vertical.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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);
varkha 2017/04/27 03:04:29 s/2/kButtonCornerRadius ?
Evan Stade 2017/04/27 17:36:29 I prefer not to used named constants for values th
78
79 // Craft the left arrow.
80 SkRect arrow = SkRect::MakeXYWH(4, 28, 4, 8);
varkha 2017/04/27 03:04:29 How about arrow_rect?
varkha 2017/04/27 03:04:29 I can see that XYWH makes it less ambiguous but I
Evan Stade 2017/04/27 17:36:29 changed to kArrowRect
Evan Stade 2017/04/27 17:36:29 Indeed, the XYHW serve as names. The only differen
81 SkPath path;
82 path.moveTo(arrow.right(), arrow.y());
83 path.lineTo(arrow.x(), arrow.centerY());
84 path.lineTo(arrow.right(), arrow.bottom());
85 path.close();
86
87 // Do the same for the right arrow.
88 arrow = arrow.makeOffset(kShortSide - arrow.width() - arrow.x() * 2, 0);
89 path.moveTo(arrow.x(), arrow.y());
90 path.lineTo(arrow.right(), arrow.centerY());
91 path.lineTo(arrow.x(), arrow.bottom());
92 path.close();
93
94 // The arrows are drawn for the vertical orientation; flip if need be.
95 if (direction_ == TOP_BOTTOM) {
96 SkMatrix transform;
97 constexpr int kHalfShort = kShortSide / 2;
98 constexpr int kHalfLong = kLongSide / 2;
99 transform.setRotate(90, kHalfShort, kHalfLong);
100 transform.postTranslate(kHalfLong - kHalfShort, kHalfShort - kHalfLong);
101 path.transform(transform);
102 }
103
104 flags.setColor(SK_ColorWHITE);
105 canvas->DrawPath(path, flags);
80 } 106 }
107
81 bool OnMousePressed(const ui::MouseEvent& event) override { 108 bool OnMousePressed(const ui::MouseEvent& event) override {
82 gfx::Point location(event.location()); 109 gfx::Point location(event.location());
83 views::View::ConvertPointToScreen(this, &location); 110 views::View::ConvertPointToScreen(this, &location);
84 controller_->StartResize(location); 111 controller_->StartResize(location);
85 return true; 112 return true;
86 } 113 }
114
87 bool OnMouseDragged(const ui::MouseEvent& event) override { 115 bool OnMouseDragged(const ui::MouseEvent& event) override {
88 gfx::Point location(event.location()); 116 gfx::Point location(event.location());
89 views::View::ConvertPointToScreen(this, &location); 117 views::View::ConvertPointToScreen(this, &location);
90 controller_->Resize(location, event.flags()); 118 controller_->Resize(location, event.flags());
91 return true; 119 return true;
92 } 120 }
121
93 void OnMouseReleased(const ui::MouseEvent& event) override { 122 void OnMouseReleased(const ui::MouseEvent& event) override {
94 controller_->CompleteResize(); 123 controller_->CompleteResize();
95 } 124 }
125
96 void OnMouseCaptureLost() override { controller_->CancelResize(); } 126 void OnMouseCaptureLost() override { controller_->CancelResize(); }
127
97 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override { 128 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override {
98 int component = (direction_ == LEFT_RIGHT) ? HTRIGHT : HTBOTTOM; 129 int component = (direction_ == LEFT_RIGHT) ? HTRIGHT : HTBOTTOM;
99 return ::wm::CompoundEventFilter::CursorForWindowComponent(component); 130 return ::wm::CompoundEventFilter::CursorForWindowComponent(component);
100 } 131 }
101 132
102 private: 133 private:
134 static constexpr int kLongSide = 64;
135 static constexpr int kShortSide = 28;
136
103 MultiWindowResizeController* controller_; 137 MultiWindowResizeController* controller_;
104 const Direction direction_; 138 const Direction direction_;
105 const gfx::ImageSkia* image_;
106 139
107 DISALLOW_COPY_AND_ASSIGN(ResizeView); 140 DISALLOW_COPY_AND_ASSIGN(ResizeView);
108 }; 141 };
109 142
110 // MouseWatcherHost implementation for MultiWindowResizeController. Forwards 143 // MouseWatcherHost implementation for MultiWindowResizeController. Forwards
111 // Contains() to MultiWindowResizeController. 144 // Contains() to MultiWindowResizeController.
112 class MultiWindowResizeController::ResizeMouseWatcherHost 145 class MultiWindowResizeController::ResizeMouseWatcherHost
113 : public views::MouseWatcherHost { 146 : public views::MouseWatcherHost {
114 public: 147 public:
115 ResizeMouseWatcherHost(MultiWindowResizeController* host) : host_(host) {} 148 ResizeMouseWatcherHost(MultiWindowResizeController* host) : host_(host) {}
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 564
532 bool MultiWindowResizeController::IsOverComponent( 565 bool MultiWindowResizeController::IsOverComponent(
533 WmWindow* window, 566 WmWindow* window,
534 const gfx::Point& location_in_screen, 567 const gfx::Point& location_in_screen,
535 int component) const { 568 int component) const {
536 gfx::Point window_loc = window->ConvertPointFromScreen(location_in_screen); 569 gfx::Point window_loc = window->ConvertPointFromScreen(location_in_screen);
537 return window->GetNonClientComponent(window_loc) == component; 570 return window->GetNonClientComponent(window_loc) == component;
538 } 571 }
539 572
540 } // namespace ash 573 } // namespace ash
OLDNEW
« no previous file with comments | « ash/resources/default_200_percent/common/multi_window_resize_vertical.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698