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

Side by Side Diff: apps/ui/views/app_window_frame_view.cc

Issue 210363004: Linux: App windows with frame: chrome and no color are now native. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't need not IsFrameless(); that is implied by has_frame_color_. Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "apps/ui/views/app_window_frame_view.h" 5 #include "apps/ui/views/app_window_frame_view.h"
6 6
7 #include "apps/ui/native_app_window.h"
8 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
9 #include "extensions/common/draggable_region.h" 8 #include "extensions/common/draggable_region.h"
10 #include "grit/theme_resources.h" 9 #include "grit/theme_resources.h"
11 #include "grit/ui_strings.h" // Accessibility names 10 #include "grit/ui_strings.h" // Accessibility names
12 #include "third_party/skia/include/core/SkPaint.h" 11 #include "third_party/skia/include/core/SkPaint.h"
12 #include "third_party/skia/include/core/SkRegion.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 #include "ui/views/widget/widget_delegate.h" 23 #include "ui/views/widget/widget_delegate.h"
24 24
25 #if defined(USE_AURA) 25 #if defined(USE_AURA)
26 #include "ui/aura/env.h" 26 #include "ui/aura/env.h"
27 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
28 #endif 28 #endif
29 29
30 namespace { 30 namespace {
31 // Height of the chrome-style caption, in pixels. 31 // Height of the chrome-style caption, in pixels.
32 const int kCaptionHeight = 25; 32 const int kCaptionHeight = 25;
33 } // namespace 33 } // namespace
34 34
35 namespace apps { 35 namespace apps {
36 36
37 const char AppWindowFrameView::kViewClassName[] = 37 const char AppWindowFrameView::kViewClassName[] =
38 "browser/ui/views/extensions/AppWindowFrameView"; 38 "browser/ui/views/extensions/AppWindowFrameView";
39 39
40 AppWindowFrameView::AppWindowFrameView(NativeAppWindow* window) 40 AppWindowFrameView::AppWindowFrameView()
41 : window_(window), 41 : widget_(NULL),
42 widget_(NULL), 42 draggable_region_(NULL),
43 close_button_(NULL), 43 close_button_(NULL),
44 maximize_button_(NULL), 44 maximize_button_(NULL),
45 restore_button_(NULL), 45 restore_button_(NULL),
46 minimize_button_(NULL), 46 minimize_button_(NULL),
47 resize_inside_bounds_size_(0), 47 resize_inside_bounds_size_(0),
48 resize_outside_bounds_size_(0), 48 resize_outside_bounds_size_(0),
49 resize_area_corner_size_(0) {} 49 resize_area_corner_size_(0) {}
50 50
51 AppWindowFrameView::~AppWindowFrameView() {} 51 AppWindowFrameView::~AppWindowFrameView() {}
52 52
53 void AppWindowFrameView::Init(views::Widget* widget, 53 void AppWindowFrameView::Init(views::Widget* widget,
54 bool draw_frame,
54 const SkColor& frame_color, 55 const SkColor& frame_color,
56 const SkRegion* draggable_region,
55 int resize_inside_bounds_size, 57 int resize_inside_bounds_size,
56 int resize_outside_bounds_size, 58 int resize_outside_bounds_size,
57 int resize_outside_scale_for_touch, 59 int resize_outside_scale_for_touch,
58 int resize_area_corner_size) { 60 int resize_area_corner_size) {
59 widget_ = widget; 61 widget_ = widget;
62 draw_frame_ = draw_frame;
60 frame_color_ = frame_color; 63 frame_color_ = frame_color;
64 draggable_region_ = draggable_region;
61 resize_inside_bounds_size_ = resize_inside_bounds_size; 65 resize_inside_bounds_size_ = resize_inside_bounds_size;
62 resize_outside_bounds_size_ = resize_outside_bounds_size; 66 resize_outside_bounds_size_ = resize_outside_bounds_size;
63 resize_area_corner_size_ = resize_area_corner_size; 67 resize_area_corner_size_ = resize_area_corner_size;
64 68
65 if (!window_->IsFrameless()) { 69 if (draw_frame) {
66 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 70 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
67 close_button_ = new views::ImageButton(this); 71 close_button_ = new views::ImageButton(this);
68 close_button_->SetImage( 72 close_button_->SetImage(
69 views::CustomButton::STATE_NORMAL, 73 views::CustomButton::STATE_NORMAL,
70 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); 74 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia());
71 close_button_->SetImage( 75 close_button_->SetImage(
72 views::CustomButton::STATE_HOVERED, 76 views::CustomButton::STATE_HOVERED,
73 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); 77 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia());
74 close_button_->SetImage( 78 close_button_->SetImage(
75 views::CustomButton::STATE_PRESSED, 79 views::CustomButton::STATE_PRESSED,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); 122 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia());
119 minimize_button_->SetAccessibleName( 123 minimize_button_->SetAccessibleName(
120 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); 124 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE));
121 AddChildView(minimize_button_); 125 AddChildView(minimize_button_);
122 } 126 }
123 } 127 }
124 128
125 // views::NonClientFrameView implementation. 129 // views::NonClientFrameView implementation.
126 130
127 gfx::Rect AppWindowFrameView::GetBoundsForClientView() const { 131 gfx::Rect AppWindowFrameView::GetBoundsForClientView() const {
128 if (window_->IsFrameless() || widget_->IsFullscreen()) 132 if (!draw_frame_ || widget_->IsFullscreen())
129 return bounds(); 133 return bounds();
130 return gfx::Rect( 134 return gfx::Rect(
131 0, kCaptionHeight, width(), std::max(0, height() - kCaptionHeight)); 135 0, kCaptionHeight, width(), std::max(0, height() - kCaptionHeight));
132 } 136 }
133 137
134 gfx::Rect AppWindowFrameView::GetWindowBoundsForClientBounds( 138 gfx::Rect AppWindowFrameView::GetWindowBoundsForClientBounds(
135 const gfx::Rect& client_bounds) const { 139 const gfx::Rect& client_bounds) const {
136 if (window_->IsFrameless()) { 140 gfx::Rect window_bounds = client_bounds;
137 gfx::Rect window_bounds = client_bounds; 141 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
142 // Get the difference between the widget's client area bounds and window
143 // bounds, and grow |window_bounds| by that amount.
144 gfx::Insets native_frame_insets =
145 widget_->GetClientAreaBoundsInScreen().InsetsFrom(
146 widget_->GetWindowBoundsInScreen());
147 window_bounds.Inset(native_frame_insets);
148 #endif
149 if (!draw_frame_) {
138 // Enforce minimum size (1, 1) in case that client_bounds is passed with 150 // Enforce minimum size (1, 1) in case that client_bounds is passed with
139 // empty size. This could occur when the frameless window is being 151 // empty size. This could occur when the frameless window is being
140 // initialized. 152 // initialized.
141 if (window_bounds.IsEmpty()) { 153 if (window_bounds.IsEmpty()) {
142 window_bounds.set_width(1); 154 window_bounds.set_width(1);
143 window_bounds.set_height(1); 155 window_bounds.set_height(1);
144 } 156 }
145 return window_bounds; 157 return window_bounds;
146 } 158 }
147 159
148 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; 160 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2;
149 int header_width = close_button_->width() + closeButtonOffsetX * 2; 161 int header_width = close_button_->width() + closeButtonOffsetX * 2;
150 return gfx::Rect(client_bounds.x(), 162 return gfx::Rect(window_bounds.x(),
151 client_bounds.y() - kCaptionHeight, 163 window_bounds.y() - kCaptionHeight,
152 std::max(header_width, client_bounds.width()), 164 std::max(header_width, window_bounds.width()),
153 client_bounds.height() + kCaptionHeight); 165 window_bounds.height() + kCaptionHeight);
154 } 166 }
155 167
156 int AppWindowFrameView::NonClientHitTest(const gfx::Point& point) { 168 int AppWindowFrameView::NonClientHitTest(const gfx::Point& point) {
157 if (widget_->IsFullscreen()) 169 if (widget_->IsFullscreen())
158 return HTCLIENT; 170 return HTCLIENT;
159 171
160 gfx::Rect expanded_bounds = bounds(); 172 gfx::Rect expanded_bounds = bounds();
161 if (resize_outside_bounds_size_) { 173 if (resize_outside_bounds_size_) {
162 expanded_bounds.Inset(gfx::Insets(-resize_outside_bounds_size_, 174 expanded_bounds.Inset(gfx::Insets(-resize_outside_bounds_size_,
163 -resize_outside_bounds_size_, 175 -resize_outside_bounds_size_,
(...skipping 18 matching lines...) Expand all
182 resize_border, 194 resize_border,
183 resize_border, 195 resize_border,
184 resize_area_corner_size_, 196 resize_area_corner_size_,
185 resize_area_corner_size_, 197 resize_area_corner_size_,
186 can_ever_resize); 198 can_ever_resize);
187 if (frame_component != HTNOWHERE) 199 if (frame_component != HTNOWHERE)
188 return frame_component; 200 return frame_component;
189 201
190 // Check for possible draggable region in the client area for the frameless 202 // Check for possible draggable region in the client area for the frameless
191 // window. 203 // window.
192 if (window_->IsFrameless()) { 204 if (draggable_region_ && draggable_region_->contains(point.x(), point.y()))
193 SkRegion* draggable_region = window_->GetDraggableRegion(); 205 return HTCAPTION;
194 if (draggable_region && draggable_region->contains(point.x(), point.y()))
195 return HTCAPTION;
196 }
197 206
198 int client_component = widget_->client_view()->NonClientHitTest(point); 207 int client_component = widget_->client_view()->NonClientHitTest(point);
199 if (client_component != HTNOWHERE) 208 if (client_component != HTNOWHERE)
200 return client_component; 209 return client_component;
201 210
202 // Then see if the point is within any of the window controls. 211 // Then see if the point is within any of the window controls.
203 if (close_button_ && close_button_->visible() && 212 if (close_button_ && close_button_->visible() &&
204 close_button_->GetMirroredBounds().Contains(point)) { 213 close_button_->GetMirroredBounds().Contains(point)) {
205 return HTCLOSE; 214 return HTCLOSE;
206 } 215 }
(...skipping 21 matching lines...) Expand all
228 237
229 gfx::Size AppWindowFrameView::GetPreferredSize() { 238 gfx::Size AppWindowFrameView::GetPreferredSize() {
230 gfx::Size pref = widget_->client_view()->GetPreferredSize(); 239 gfx::Size pref = widget_->client_view()->GetPreferredSize();
231 gfx::Rect bounds(0, 0, pref.width(), pref.height()); 240 gfx::Rect bounds(0, 0, pref.width(), pref.height());
232 return widget_->non_client_view() 241 return widget_->non_client_view()
233 ->GetWindowBoundsForClientBounds(bounds) 242 ->GetWindowBoundsForClientBounds(bounds)
234 .size(); 243 .size();
235 } 244 }
236 245
237 void AppWindowFrameView::Layout() { 246 void AppWindowFrameView::Layout() {
238 if (window_->IsFrameless()) 247 if (!draw_frame_)
239 return; 248 return;
240 gfx::Size close_size = close_button_->GetPreferredSize(); 249 gfx::Size close_size = close_button_->GetPreferredSize();
241 const int kButtonOffsetY = 0; 250 const int kButtonOffsetY = 0;
242 const int kButtonSpacing = 1; 251 const int kButtonSpacing = 1;
243 const int kRightMargin = 3; 252 const int kRightMargin = 3;
244 253
245 close_button_->SetBounds(width() - kRightMargin - close_size.width(), 254 close_button_->SetBounds(width() - kRightMargin - close_size.width(),
246 kButtonOffsetY, 255 kButtonOffsetY,
247 close_size.width(), 256 close_size.width(),
248 close_size.height()); 257 close_size.height());
(...skipping 26 matching lines...) Expand all
275 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); 284 gfx::Size minimize_size = minimize_button_->GetPreferredSize();
276 minimize_button_->SetState(views::CustomButton::STATE_NORMAL); 285 minimize_button_->SetState(views::CustomButton::STATE_NORMAL);
277 minimize_button_->SetBounds( 286 minimize_button_->SetBounds(
278 maximize_button_->x() - kButtonSpacing - minimize_size.width(), 287 maximize_button_->x() - kButtonSpacing - minimize_size.width(),
279 kButtonOffsetY, 288 kButtonOffsetY,
280 minimize_size.width(), 289 minimize_size.width(),
281 minimize_size.height()); 290 minimize_size.height());
282 } 291 }
283 292
284 void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) { 293 void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) {
285 if (window_->IsFrameless()) 294 if (!draw_frame_)
286 return; 295 return;
287 296
288 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 297 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
289 if (ShouldPaintAsActive()) { 298 if (ShouldPaintAsActive()) {
290 close_button_->SetImage( 299 close_button_->SetImage(
291 views::CustomButton::STATE_NORMAL, 300 views::CustomButton::STATE_NORMAL,
292 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); 301 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia());
293 } else { 302 } else {
294 close_button_->SetImage( 303 close_button_->SetImage(
295 views::CustomButton::STATE_NORMAL, 304 views::CustomButton::STATE_NORMAL,
(...skipping 11 matching lines...) Expand all
307 path.lineTo(width(), kCaptionHeight); 316 path.lineTo(width(), kCaptionHeight);
308 path.lineTo(0, kCaptionHeight); 317 path.lineTo(0, kCaptionHeight);
309 path.close(); 318 path.close();
310 canvas->DrawPath(path, paint); 319 canvas->DrawPath(path, paint);
311 } 320 }
312 321
313 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } 322 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; }
314 323
315 gfx::Size AppWindowFrameView::GetMinimumSize() { 324 gfx::Size AppWindowFrameView::GetMinimumSize() {
316 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); 325 gfx::Size min_size = widget_->client_view()->GetMinimumSize();
317 if (window_->IsFrameless()) 326 if (!draw_frame_)
318 return min_size; 327 return min_size;
319 328
320 // Ensure we can display the top of the caption area. 329 // Ensure we can display the top of the caption area.
321 gfx::Rect client_bounds = GetBoundsForClientView(); 330 gfx::Rect client_bounds = GetBoundsForClientView();
322 min_size.Enlarge(0, client_bounds.y()); 331 min_size.Enlarge(0, client_bounds.y());
323 // Ensure we have enough space for the window icon and buttons. We allow 332 // Ensure we have enough space for the window icon and buttons. We allow
324 // the title string to collapse to zero width. 333 // the title string to collapse to zero width.
325 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; 334 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2;
326 int header_width = close_button_->width() + closeButtonOffsetX * 2; 335 int header_width = close_button_->width() + closeButtonOffsetX * 2;
327 if (header_width > min_size.width()) 336 if (header_width > min_size.width())
(...skipping 11 matching lines...) Expand all
339 if (max_size.height()) 348 if (max_size.height())
340 max_size.Enlarge(0, height() - client_size.height()); 349 max_size.Enlarge(0, height() - client_size.height());
341 350
342 return max_size; 351 return max_size;
343 } 352 }
344 353
345 // views::ButtonListener implementation. 354 // views::ButtonListener implementation.
346 355
347 void AppWindowFrameView::ButtonPressed(views::Button* sender, 356 void AppWindowFrameView::ButtonPressed(views::Button* sender,
348 const ui::Event& event) { 357 const ui::Event& event) {
349 DCHECK(!window_->IsFrameless()); 358 DCHECK(draw_frame_);
350 if (sender == close_button_) 359 if (sender == close_button_)
351 widget_->Close(); 360 widget_->Close();
352 else if (sender == maximize_button_) 361 else if (sender == maximize_button_)
353 widget_->Maximize(); 362 widget_->Maximize();
354 else if (sender == restore_button_) 363 else if (sender == restore_button_)
355 widget_->Restore(); 364 widget_->Restore();
356 else if (sender == minimize_button_) 365 else if (sender == minimize_button_)
357 widget_->Minimize(); 366 widget_->Minimize();
358 } 367 }
359 368
360 } // namespace apps 369 } // namespace apps
OLDNEW
« no previous file with comments | « apps/ui/views/app_window_frame_view.h ('k') | chrome/browser/ui/views/apps/chrome_native_app_window_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698