Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if (!draw_frame_) { |
| 137 gfx::Rect window_bounds = client_bounds; | 141 gfx::Rect window_bounds = client_bounds; |
| 138 // Enforce minimum size (1, 1) in case that client_bounds is passed with | 142 // 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 | 143 // empty size. This could occur when the frameless window is being |
| 140 // initialized. | 144 // initialized. |
| 141 if (window_bounds.IsEmpty()) { | 145 if (window_bounds.IsEmpty()) { |
| 142 window_bounds.set_width(1); | 146 window_bounds.set_width(1); |
| 143 window_bounds.set_height(1); | 147 window_bounds.set_height(1); |
| 144 } | 148 } |
| 145 return window_bounds; | 149 return window_bounds; |
| 146 } | 150 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 resize_border, | 186 resize_border, |
| 183 resize_border, | 187 resize_border, |
| 184 resize_area_corner_size_, | 188 resize_area_corner_size_, |
| 185 resize_area_corner_size_, | 189 resize_area_corner_size_, |
| 186 can_ever_resize); | 190 can_ever_resize); |
| 187 if (frame_component != HTNOWHERE) | 191 if (frame_component != HTNOWHERE) |
| 188 return frame_component; | 192 return frame_component; |
| 189 | 193 |
| 190 // Check for possible draggable region in the client area for the frameless | 194 // Check for possible draggable region in the client area for the frameless |
| 191 // window. | 195 // window. |
| 192 if (window_->IsFrameless()) { | 196 if (!draw_frame_) { |
|
Matt Giuca
2014/03/27 06:39:38
This part is a bit weird. On Linux, a native windo
benwells
2014/03/27 08:53:45
Yes, only frameless windows should have draggable
Matt Giuca
2014/03/27 09:16:27
Done.
Note: I did not "only set it if the window
| |
| 193 SkRegion* draggable_region = window_->GetDraggableRegion(); | 197 if (draggable_region_ && draggable_region_->contains(point.x(), point.y())) |
| 194 if (draggable_region && draggable_region->contains(point.x(), point.y())) | |
| 195 return HTCAPTION; | 198 return HTCAPTION; |
| 196 } | 199 } |
| 197 | 200 |
| 198 int client_component = widget_->client_view()->NonClientHitTest(point); | 201 int client_component = widget_->client_view()->NonClientHitTest(point); |
| 199 if (client_component != HTNOWHERE) | 202 if (client_component != HTNOWHERE) |
| 200 return client_component; | 203 return client_component; |
| 201 | 204 |
| 202 // Then see if the point is within any of the window controls. | 205 // Then see if the point is within any of the window controls. |
| 203 if (close_button_ && close_button_->visible() && | 206 if (close_button_ && close_button_->visible() && |
| 204 close_button_->GetMirroredBounds().Contains(point)) { | 207 close_button_->GetMirroredBounds().Contains(point)) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 228 | 231 |
| 229 gfx::Size AppWindowFrameView::GetPreferredSize() { | 232 gfx::Size AppWindowFrameView::GetPreferredSize() { |
| 230 gfx::Size pref = widget_->client_view()->GetPreferredSize(); | 233 gfx::Size pref = widget_->client_view()->GetPreferredSize(); |
| 231 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 234 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
| 232 return widget_->non_client_view() | 235 return widget_->non_client_view() |
| 233 ->GetWindowBoundsForClientBounds(bounds) | 236 ->GetWindowBoundsForClientBounds(bounds) |
| 234 .size(); | 237 .size(); |
| 235 } | 238 } |
| 236 | 239 |
| 237 void AppWindowFrameView::Layout() { | 240 void AppWindowFrameView::Layout() { |
| 238 if (window_->IsFrameless()) | 241 if (!draw_frame_) |
| 239 return; | 242 return; |
| 240 gfx::Size close_size = close_button_->GetPreferredSize(); | 243 gfx::Size close_size = close_button_->GetPreferredSize(); |
| 241 const int kButtonOffsetY = 0; | 244 const int kButtonOffsetY = 0; |
| 242 const int kButtonSpacing = 1; | 245 const int kButtonSpacing = 1; |
| 243 const int kRightMargin = 3; | 246 const int kRightMargin = 3; |
| 244 | 247 |
| 245 close_button_->SetBounds(width() - kRightMargin - close_size.width(), | 248 close_button_->SetBounds(width() - kRightMargin - close_size.width(), |
| 246 kButtonOffsetY, | 249 kButtonOffsetY, |
| 247 close_size.width(), | 250 close_size.width(), |
| 248 close_size.height()); | 251 close_size.height()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 275 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); | 278 gfx::Size minimize_size = minimize_button_->GetPreferredSize(); |
| 276 minimize_button_->SetState(views::CustomButton::STATE_NORMAL); | 279 minimize_button_->SetState(views::CustomButton::STATE_NORMAL); |
| 277 minimize_button_->SetBounds( | 280 minimize_button_->SetBounds( |
| 278 maximize_button_->x() - kButtonSpacing - minimize_size.width(), | 281 maximize_button_->x() - kButtonSpacing - minimize_size.width(), |
| 279 kButtonOffsetY, | 282 kButtonOffsetY, |
| 280 minimize_size.width(), | 283 minimize_size.width(), |
| 281 minimize_size.height()); | 284 minimize_size.height()); |
| 282 } | 285 } |
| 283 | 286 |
| 284 void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) { | 287 void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) { |
| 285 if (window_->IsFrameless()) | 288 if (!draw_frame_) |
| 286 return; | 289 return; |
| 287 | 290 |
| 288 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 291 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 289 if (ShouldPaintAsActive()) { | 292 if (ShouldPaintAsActive()) { |
| 290 close_button_->SetImage( | 293 close_button_->SetImage( |
| 291 views::CustomButton::STATE_NORMAL, | 294 views::CustomButton::STATE_NORMAL, |
| 292 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 295 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
| 293 } else { | 296 } else { |
| 294 close_button_->SetImage( | 297 close_button_->SetImage( |
| 295 views::CustomButton::STATE_NORMAL, | 298 views::CustomButton::STATE_NORMAL, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 307 path.lineTo(width(), kCaptionHeight); | 310 path.lineTo(width(), kCaptionHeight); |
| 308 path.lineTo(0, kCaptionHeight); | 311 path.lineTo(0, kCaptionHeight); |
| 309 path.close(); | 312 path.close(); |
| 310 canvas->DrawPath(path, paint); | 313 canvas->DrawPath(path, paint); |
| 311 } | 314 } |
| 312 | 315 |
| 313 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } | 316 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } |
| 314 | 317 |
| 315 gfx::Size AppWindowFrameView::GetMinimumSize() { | 318 gfx::Size AppWindowFrameView::GetMinimumSize() { |
| 316 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); | 319 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); |
| 317 if (window_->IsFrameless()) | 320 if (!draw_frame_) |
| 318 return min_size; | 321 return min_size; |
| 319 | 322 |
| 320 // Ensure we can display the top of the caption area. | 323 // Ensure we can display the top of the caption area. |
| 321 gfx::Rect client_bounds = GetBoundsForClientView(); | 324 gfx::Rect client_bounds = GetBoundsForClientView(); |
| 322 min_size.Enlarge(0, client_bounds.y()); | 325 min_size.Enlarge(0, client_bounds.y()); |
| 323 // Ensure we have enough space for the window icon and buttons. We allow | 326 // Ensure we have enough space for the window icon and buttons. We allow |
| 324 // the title string to collapse to zero width. | 327 // the title string to collapse to zero width. |
| 325 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; | 328 int closeButtonOffsetX = (kCaptionHeight - close_button_->height()) / 2; |
| 326 int header_width = close_button_->width() + closeButtonOffsetX * 2; | 329 int header_width = close_button_->width() + closeButtonOffsetX * 2; |
| 327 if (header_width > min_size.width()) | 330 if (header_width > min_size.width()) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 339 if (max_size.height()) | 342 if (max_size.height()) |
| 340 max_size.Enlarge(0, height() - client_size.height()); | 343 max_size.Enlarge(0, height() - client_size.height()); |
| 341 | 344 |
| 342 return max_size; | 345 return max_size; |
| 343 } | 346 } |
| 344 | 347 |
| 345 // views::ButtonListener implementation. | 348 // views::ButtonListener implementation. |
| 346 | 349 |
| 347 void AppWindowFrameView::ButtonPressed(views::Button* sender, | 350 void AppWindowFrameView::ButtonPressed(views::Button* sender, |
| 348 const ui::Event& event) { | 351 const ui::Event& event) { |
| 349 DCHECK(!window_->IsFrameless()); | 352 DCHECK(draw_frame_); |
| 350 if (sender == close_button_) | 353 if (sender == close_button_) |
| 351 widget_->Close(); | 354 widget_->Close(); |
| 352 else if (sender == maximize_button_) | 355 else if (sender == maximize_button_) |
| 353 widget_->Maximize(); | 356 widget_->Maximize(); |
| 354 else if (sender == restore_button_) | 357 else if (sender == restore_button_) |
| 355 widget_->Restore(); | 358 widget_->Restore(); |
| 356 else if (sender == minimize_button_) | 359 else if (sender == minimize_button_) |
| 357 widget_->Minimize(); | 360 widget_->Minimize(); |
| 358 } | 361 } |
| 359 | 362 |
| 360 } // namespace apps | 363 } // namespace apps |
| OLD | NEW |