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 "chrome/browser/ui/views/extensions/shell_window_frame_view.h" | 5 #include "apps/ui/views/shell_window_frame_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/apps/native_app_window_views.h" | 8 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
stevenjb
2013/10/12 00:16:42
Is the intention to check this in with the chrome
| |
9 #include "extensions/common/draggable_region.h" | 9 #include "extensions/common/draggable_region.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
11 #include "grit/ui_strings.h" // Accessibility names | 11 #include "grit/ui_strings.h" // Accessibility names |
12 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
13 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
19 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
20 #include "ui/views/layout/grid_layout.h" | 20 #include "ui/views/layout/grid_layout.h" |
21 #include "ui/views/views_delegate.h" | 21 #include "ui/views/views_delegate.h" |
22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
23 | 23 |
24 #if defined(OS_WIN) && !defined(USE_AURA) | 24 #if defined(USE_AURA) |
25 #include "chrome/browser/shell_integration.h" | |
26 #include "chrome/browser/web_applications/web_app.h" | |
27 #include "ui/base/win/shell.h" | |
28 #endif | |
29 | |
30 #if defined(USE_ASH) | |
31 #include "ash/ash_constants.h" | |
32 #include "chrome/browser/ui/ash/ash_util.h" | |
33 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
34 #endif | |
35 | |
36 #if defined(USE_AURA) | |
37 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
38 #endif | 27 #endif |
39 | 28 |
40 namespace { | 29 namespace { |
41 const int kResizeInsideBoundsSize = 5; | |
42 const int kResizeAreaCornerSize = 16; | |
43 | |
44 // Height of the chrome-style caption, in pixels. | 30 // Height of the chrome-style caption, in pixels. |
45 const int kCaptionHeight = 25; | 31 const int kCaptionHeight = 25; |
46 } // namespace | 32 } // namespace |
47 | 33 |
34 namespace apps { | |
48 | 35 |
49 const char ShellWindowFrameView::kViewClassName[] = | 36 const char ShellWindowFrameView::kViewClassName[] = |
50 "browser/ui/views/extensions/ShellWindowFrameView"; | 37 "browser/ui/views/extensions/ShellWindowFrameView"; |
51 | 38 |
52 ShellWindowFrameView::ShellWindowFrameView(NativeAppWindowViews* window) | 39 ShellWindowFrameView::ShellWindowFrameView(NativeAppWindowViews* window) |
53 : window_(window), | 40 : window_(window), |
54 frame_(NULL), | 41 frame_(NULL), |
55 close_button_(NULL) { | 42 close_button_(NULL), |
43 maximize_button_(NULL), | |
44 restore_button_(NULL), | |
45 minimize_button_(NULL), | |
46 resize_inside_bounds_size_(0), | |
47 resize_area_corner_size_(0) { | |
56 } | 48 } |
57 | 49 |
58 ShellWindowFrameView::~ShellWindowFrameView() { | 50 ShellWindowFrameView::~ShellWindowFrameView() { |
59 } | 51 } |
60 | 52 |
61 void ShellWindowFrameView::Init(views::Widget* frame) { | 53 void ShellWindowFrameView::Init(views::Widget* frame, |
54 int resize_inside_bounds_size, | |
55 int resize_outside_bounds_size, | |
56 int resize_outside_scale_for_touch, | |
57 int resize_area_corner_size) { | |
62 frame_ = frame; | 58 frame_ = frame; |
59 resize_inside_bounds_size_ = resize_inside_bounds_size; | |
60 resize_area_corner_size_ = resize_area_corner_size; | |
63 | 61 |
64 if (!window_->frameless()) { | 62 if (!window_->frameless()) { |
65 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
66 close_button_ = new views::ImageButton(this); | 64 close_button_ = new views::ImageButton(this); |
67 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 65 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
68 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 66 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
69 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 67 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
70 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); | 68 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); |
71 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 69 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
72 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); | 70 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); |
(...skipping 28 matching lines...) Expand all Loading... | |
101 minimize_button_->SetImage(views::CustomButton::STATE_HOVERED, | 99 minimize_button_->SetImage(views::CustomButton::STATE_HOVERED, |
102 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); | 100 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); |
103 minimize_button_->SetImage(views::CustomButton::STATE_PRESSED, | 101 minimize_button_->SetImage(views::CustomButton::STATE_PRESSED, |
104 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); | 102 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); |
105 minimize_button_->SetAccessibleName( | 103 minimize_button_->SetAccessibleName( |
106 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 104 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
107 AddChildView(minimize_button_); | 105 AddChildView(minimize_button_); |
108 } | 106 } |
109 | 107 |
110 #if defined(USE_AURA) | 108 #if defined(USE_AURA) |
111 int resize_inside_bounds_size = kResizeInsideBoundsSize; | |
112 aura::Window* window = frame->GetNativeWindow(); | 109 aura::Window* window = frame->GetNativeWindow(); |
113 #if defined(USE_ASH) | 110 // Some Aura implementations (Ash) allow resize handles outside the window. |
114 if (chrome::IsNativeWindowInAsh(window)) { | 111 if (resize_outside_bounds_size > 0) { |
115 gfx::Insets mouse_insets = gfx::Insets(-ash::kResizeOutsideBoundsSize, | 112 gfx::Insets mouse_insets = gfx::Insets(-resize_outside_bounds_size, |
116 -ash::kResizeOutsideBoundsSize, | 113 -resize_outside_bounds_size, |
117 -ash::kResizeOutsideBoundsSize, | 114 -resize_outside_bounds_size, |
118 -ash::kResizeOutsideBoundsSize); | 115 -resize_outside_bounds_size); |
119 gfx::Insets touch_insets = mouse_insets.Scale( | 116 gfx::Insets touch_insets = |
120 ash::kResizeOutsideBoundsScaleForTouch); | 117 mouse_insets.Scale(resize_outside_scale_for_touch); |
121 // Ensure we get resize cursors for a few pixels outside our bounds. | 118 // Ensure we get resize cursors for a few pixels outside our bounds. |
122 window->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); | 119 window->SetHitTestBoundsOverrideOuter(mouse_insets, touch_insets); |
123 | |
124 // If the window is in ash, the inside area used for resizing will be | |
125 // smaller due to the fact that outside area is also used for resizing. | |
126 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | |
127 } | 120 } |
128 #endif | |
129 // Ensure we get resize cursors just inside our bounds as well. | 121 // Ensure we get resize cursors just inside our bounds as well. |
130 // TODO(jeremya): do we need to update these when in fullscreen/maximized? | 122 // TODO(jeremya): do we need to update these when in fullscreen/maximized? |
131 window->set_hit_test_bounds_override_inner( | 123 window->set_hit_test_bounds_override_inner( |
132 gfx::Insets(resize_inside_bounds_size, resize_inside_bounds_size, | 124 gfx::Insets(resize_inside_bounds_size_, resize_inside_bounds_size_, |
133 resize_inside_bounds_size, resize_inside_bounds_size)); | 125 resize_inside_bounds_size_, resize_inside_bounds_size_)); |
134 #endif | 126 #endif |
135 } | 127 } |
136 | 128 |
137 // views::NonClientFrameView implementation. | 129 // views::NonClientFrameView implementation. |
138 | 130 |
139 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { | 131 gfx::Rect ShellWindowFrameView::GetBoundsForClientView() const { |
140 if (window_->frameless() || frame_->IsFullscreen()) | 132 if (window_->frameless() || frame_->IsFullscreen()) |
141 return bounds(); | 133 return bounds(); |
142 return gfx::Rect(0, kCaptionHeight, width(), | 134 return gfx::Rect(0, kCaptionHeight, width(), |
143 std::max(0, height() - kCaptionHeight)); | 135 std::max(0, height() - kCaptionHeight)); |
(...skipping 19 matching lines...) Expand all Loading... | |
163 return gfx::Rect(client_bounds.x(), | 155 return gfx::Rect(client_bounds.x(), |
164 std::max(0, client_bounds.y() - kCaptionHeight), | 156 std::max(0, client_bounds.y() - kCaptionHeight), |
165 std::max(header_width, client_bounds.width()), | 157 std::max(header_width, client_bounds.width()), |
166 client_bounds.height() + kCaptionHeight); | 158 client_bounds.height() + kCaptionHeight); |
167 } | 159 } |
168 | 160 |
169 int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) { | 161 int ShellWindowFrameView::NonClientHitTest(const gfx::Point& point) { |
170 if (frame_->IsFullscreen()) | 162 if (frame_->IsFullscreen()) |
171 return HTCLIENT; | 163 return HTCLIENT; |
172 | 164 |
173 int resize_inside_bounds_size = kResizeInsideBoundsSize; | 165 gfx::Rect expanded_bounds = bounds(); |
174 int resize_area_corner_size = kResizeAreaCornerSize; | 166 #if defined(USE_AURA) |
175 | 167 // Some Aura implementations (Ash) optionally allow resize handles just |
176 #if defined(USE_ASH) | 168 // outside the window bounds. |
177 aura::Window* window = frame_->GetNativeWindow(); | 169 aura::Window* window = frame_->GetNativeWindow(); |
178 if (chrome::IsNativeWindowInAsh(window)) { | 170 if (aura::Env::GetInstance()->is_touch_down()) |
179 gfx::Rect expanded_bounds = bounds(); | 171 expanded_bounds.Inset(window->hit_test_bounds_override_outer_touch()); |
James Cook
2013/10/11 23:05:06
These bounds override insets are 0 in the normal (
| |
180 int outside_bounds = ash::kResizeOutsideBoundsSize; | 172 else |
181 if (aura::Env::GetInstance()->is_touch_down()) | 173 expanded_bounds.Inset(window->hit_test_bounds_override_outer_mouse()); |
182 outside_bounds *= ash::kResizeOutsideBoundsScaleForTouch; | |
183 expanded_bounds.Inset(-outside_bounds, -outside_bounds); | |
184 if (!expanded_bounds.Contains(point)) | |
James Cook
2013/10/11 23:05:06
This was subtly wrong - the code should have been
| |
185 return HTNOWHERE; | |
186 | |
187 resize_inside_bounds_size = ash::kResizeInsideBoundsSize; | |
188 resize_area_corner_size = ash::kResizeAreaCornerSize; | |
189 } | |
190 #endif | 174 #endif |
175 // Points outside the (possibly expanded) bounds can be discarded. | |
176 if (!expanded_bounds.Contains(point)) | |
177 return HTNOWHERE; | |
191 | 178 |
192 // Check the frame first, as we allow a small area overlapping the contents | 179 // Check the frame first, as we allow a small area overlapping the contents |
193 // to be used for resize handles. | 180 // to be used for resize handles. |
194 bool can_ever_resize = frame_->widget_delegate() ? | 181 bool can_ever_resize = frame_->widget_delegate() ? |
195 frame_->widget_delegate()->CanResize() : | 182 frame_->widget_delegate()->CanResize() : |
196 false; | 183 false; |
197 // Don't allow overlapping resize handles when the window is maximized or | 184 // Don't allow overlapping resize handles when the window is maximized or |
198 // fullscreen, as it can't be resized in those states. | 185 // fullscreen, as it can't be resized in those states. |
199 int resize_border = | 186 int resize_border = |
200 (frame_->IsMaximized() || frame_->IsFullscreen()) ? 0 : | 187 (frame_->IsMaximized() || frame_->IsFullscreen()) ? 0 : |
201 resize_inside_bounds_size; | 188 resize_inside_bounds_size_; |
202 int frame_component = GetHTComponentForFrame(point, | 189 int frame_component = GetHTComponentForFrame(point, |
203 resize_border, | 190 resize_border, |
204 resize_border, | 191 resize_border, |
205 resize_area_corner_size, | 192 resize_area_corner_size_, |
206 resize_area_corner_size, | 193 resize_area_corner_size_, |
207 can_ever_resize); | 194 can_ever_resize); |
208 if (frame_component != HTNOWHERE) | 195 if (frame_component != HTNOWHERE) |
209 return frame_component; | 196 return frame_component; |
210 | 197 |
211 // Check for possible draggable region in the client area for the frameless | 198 // Check for possible draggable region in the client area for the frameless |
212 // window. | 199 // window. |
213 if (window_->frameless() && | 200 if (window_->frameless() && |
214 window_->draggable_region() && | 201 window_->draggable_region() && |
215 window_->draggable_region()->contains(point.x(), point.y())) | 202 window_->draggable_region()->contains(point.x(), point.y())) |
216 return HTCAPTION; | 203 return HTCAPTION; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 DCHECK(!window_->frameless()); | 348 DCHECK(!window_->frameless()); |
362 if (sender == close_button_) | 349 if (sender == close_button_) |
363 frame_->Close(); | 350 frame_->Close(); |
364 else if (sender == maximize_button_) | 351 else if (sender == maximize_button_) |
365 frame_->Maximize(); | 352 frame_->Maximize(); |
366 else if (sender == restore_button_) | 353 else if (sender == restore_button_) |
367 frame_->Restore(); | 354 frame_->Restore(); |
368 else if (sender == minimize_button_) | 355 else if (sender == minimize_button_) |
369 frame_->Minimize(); | 356 frame_->Minimize(); |
370 } | 357 } |
358 | |
359 } // namespace apps | |
OLD | NEW |