| 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" | 7 #include "apps/ui/native_app_window.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 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 "third_party/skia/include/core/SkRegion.h" | 13 #include "third_party/skia/include/core/SkRegion.h" |
| 14 #include "ui/base/hit_test.h" | 14 #include "ui/base/hit_test.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/color_utils.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 19 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
| 20 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
| 21 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
| 22 #include "ui/views/views_delegate.h" | 23 #include "ui/views/views_delegate.h" |
| 23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 24 #include "ui/views/widget/widget_delegate.h" | 25 #include "ui/views/widget/widget_delegate.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 67 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
| 67 close_button_->SetImage( | 68 close_button_->SetImage( |
| 68 views::CustomButton::STATE_HOVERED, | 69 views::CustomButton::STATE_HOVERED, |
| 69 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); | 70 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_H).ToImageSkia()); |
| 70 close_button_->SetImage( | 71 close_button_->SetImage( |
| 71 views::CustomButton::STATE_PRESSED, | 72 views::CustomButton::STATE_PRESSED, |
| 72 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); | 73 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_P).ToImageSkia()); |
| 73 close_button_->SetAccessibleName( | 74 close_button_->SetAccessibleName( |
| 74 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 75 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 75 AddChildView(close_button_); | 76 AddChildView(close_button_); |
| 77 // STATE_NORMAL images are set in SetButtonImagesForFrame, not here. |
| 76 maximize_button_ = new views::ImageButton(this); | 78 maximize_button_ = new views::ImageButton(this); |
| 77 maximize_button_->SetImage( | 79 maximize_button_->SetImage( |
| 78 views::CustomButton::STATE_NORMAL, | |
| 79 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia()); | |
| 80 maximize_button_->SetImage( | |
| 81 views::CustomButton::STATE_HOVERED, | 80 views::CustomButton::STATE_HOVERED, |
| 82 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia()); | 81 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia()); |
| 83 maximize_button_->SetImage( | 82 maximize_button_->SetImage( |
| 84 views::CustomButton::STATE_PRESSED, | 83 views::CustomButton::STATE_PRESSED, |
| 85 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_P).ToImageSkia()); | 84 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_P).ToImageSkia()); |
| 86 maximize_button_->SetImage( | 85 maximize_button_->SetImage( |
| 87 views::CustomButton::STATE_DISABLED, | 86 views::CustomButton::STATE_DISABLED, |
| 88 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_D).ToImageSkia()); | 87 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_D).ToImageSkia()); |
| 89 maximize_button_->SetAccessibleName( | 88 maximize_button_->SetAccessibleName( |
| 90 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); | 89 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); |
| 91 AddChildView(maximize_button_); | 90 AddChildView(maximize_button_); |
| 92 restore_button_ = new views::ImageButton(this); | 91 restore_button_ = new views::ImageButton(this); |
| 93 restore_button_->SetImage( | 92 restore_button_->SetImage( |
| 94 views::CustomButton::STATE_NORMAL, | |
| 95 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia()); | |
| 96 restore_button_->SetImage( | |
| 97 views::CustomButton::STATE_HOVERED, | 93 views::CustomButton::STATE_HOVERED, |
| 98 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia()); | 94 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia()); |
| 99 restore_button_->SetImage( | 95 restore_button_->SetImage( |
| 100 views::CustomButton::STATE_PRESSED, | 96 views::CustomButton::STATE_PRESSED, |
| 101 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_P).ToImageSkia()); | 97 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_P).ToImageSkia()); |
| 102 restore_button_->SetAccessibleName( | 98 restore_button_->SetAccessibleName( |
| 103 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); | 99 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); |
| 104 AddChildView(restore_button_); | 100 AddChildView(restore_button_); |
| 105 minimize_button_ = new views::ImageButton(this); | 101 minimize_button_ = new views::ImageButton(this); |
| 106 minimize_button_->SetImage( | 102 minimize_button_->SetImage( |
| 107 views::CustomButton::STATE_NORMAL, | |
| 108 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia()); | |
| 109 minimize_button_->SetImage( | |
| 110 views::CustomButton::STATE_HOVERED, | 103 views::CustomButton::STATE_HOVERED, |
| 111 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); | 104 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); |
| 112 minimize_button_->SetImage( | 105 minimize_button_->SetImage( |
| 113 views::CustomButton::STATE_PRESSED, | 106 views::CustomButton::STATE_PRESSED, |
| 114 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); | 107 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_P).ToImageSkia()); |
| 115 minimize_button_->SetAccessibleName( | 108 minimize_button_->SetAccessibleName( |
| 116 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 109 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 117 AddChildView(minimize_button_); | 110 AddChildView(minimize_button_); |
| 111 |
| 112 SetButtonImagesForFrame(); |
| 118 } | 113 } |
| 119 } | 114 } |
| 120 | 115 |
| 121 void AppWindowFrameView::SetResizeSizes(int resize_inside_bounds_size, | 116 void AppWindowFrameView::SetResizeSizes(int resize_inside_bounds_size, |
| 122 int resize_outside_bounds_size, | 117 int resize_outside_bounds_size, |
| 123 int resize_area_corner_size) { | 118 int resize_area_corner_size) { |
| 124 resize_inside_bounds_size_ = resize_inside_bounds_size; | 119 resize_inside_bounds_size_ = resize_inside_bounds_size; |
| 125 resize_outside_bounds_size_ = resize_outside_bounds_size; | 120 resize_outside_bounds_size_ = resize_outside_bounds_size; |
| 126 resize_area_corner_size_ = resize_area_corner_size; | 121 resize_area_corner_size_ = resize_area_corner_size; |
| 127 } | 122 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (ShouldPaintAsActive()) { | 292 if (ShouldPaintAsActive()) { |
| 298 close_button_->SetImage( | 293 close_button_->SetImage( |
| 299 views::CustomButton::STATE_NORMAL, | 294 views::CustomButton::STATE_NORMAL, |
| 300 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); | 295 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE).ToImageSkia()); |
| 301 } else { | 296 } else { |
| 302 close_button_->SetImage( | 297 close_button_->SetImage( |
| 303 views::CustomButton::STATE_NORMAL, | 298 views::CustomButton::STATE_NORMAL, |
| 304 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); | 299 rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); |
| 305 } | 300 } |
| 306 | 301 |
| 307 // TODO(jeremya): different look for inactive? | 302 SetButtonImagesForFrame(); |
| 303 // TODO(benwells): different look for inactive by default. |
| 308 SkPaint paint; | 304 SkPaint paint; |
| 309 paint.setAntiAlias(false); | 305 paint.setAntiAlias(false); |
| 310 paint.setStyle(SkPaint::kFill_Style); | 306 paint.setStyle(SkPaint::kFill_Style); |
| 311 if (widget_->IsActive()) | 307 paint.setColor(CurrentFrameColor()); |
| 312 paint.setColor(active_frame_color_); | |
| 313 else | |
| 314 paint.setColor(inactive_frame_color_); | |
| 315 gfx::Path path; | 308 gfx::Path path; |
| 316 path.moveTo(0, 0); | 309 path.moveTo(0, 0); |
| 317 path.lineTo(width(), 0); | 310 path.lineTo(width(), 0); |
| 318 path.lineTo(width(), kCaptionHeight); | 311 path.lineTo(width(), kCaptionHeight); |
| 319 path.lineTo(0, kCaptionHeight); | 312 path.lineTo(0, kCaptionHeight); |
| 320 path.close(); | 313 path.close(); |
| 321 canvas->DrawPath(path, paint); | 314 canvas->DrawPath(path, paint); |
| 322 } | 315 } |
| 323 | 316 |
| 324 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } | 317 const char* AppWindowFrameView::GetClassName() const { return kViewClassName; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 if (sender == close_button_) | 352 if (sender == close_button_) |
| 360 widget_->Close(); | 353 widget_->Close(); |
| 361 else if (sender == maximize_button_) | 354 else if (sender == maximize_button_) |
| 362 widget_->Maximize(); | 355 widget_->Maximize(); |
| 363 else if (sender == restore_button_) | 356 else if (sender == restore_button_) |
| 364 widget_->Restore(); | 357 widget_->Restore(); |
| 365 else if (sender == minimize_button_) | 358 else if (sender == minimize_button_) |
| 366 widget_->Minimize(); | 359 widget_->Minimize(); |
| 367 } | 360 } |
| 368 | 361 |
| 362 SkColor AppWindowFrameView::CurrentFrameColor() { |
| 363 return widget_->IsActive() ? active_frame_color_ : inactive_frame_color_; |
| 364 } |
| 365 |
| 366 void AppWindowFrameView::SetButtonImagesForFrame() { |
| 367 DCHECK(draw_frame_); |
| 368 |
| 369 // If the frame is dark, we should use the light images so they have |
| 370 // some contrast. |
| 371 unsigned char frame_luma = |
| 372 color_utils::GetLuminanceForColor(CurrentFrameColor()); |
| 373 const unsigned char kLuminanceThreshold = 100; |
| 374 bool use_light = frame_luma < kLuminanceThreshold; |
| 375 |
| 376 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 377 if (use_light) { |
| 378 maximize_button_->SetImage( |
| 379 views::CustomButton::STATE_NORMAL, |
| 380 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_L).ToImageSkia()); |
| 381 restore_button_->SetImage( |
| 382 views::CustomButton::STATE_NORMAL, |
| 383 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_L).ToImageSkia()); |
| 384 minimize_button_->SetImage( |
| 385 views::CustomButton::STATE_NORMAL, |
| 386 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_L).ToImageSkia()); |
| 387 } else { |
| 388 maximize_button_->SetImage( |
| 389 views::CustomButton::STATE_NORMAL, |
| 390 rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia()); |
| 391 restore_button_->SetImage( |
| 392 views::CustomButton::STATE_NORMAL, |
| 393 rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia()); |
| 394 minimize_button_->SetImage( |
| 395 views::CustomButton::STATE_NORMAL, |
| 396 rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia()); |
| 397 } |
| 398 } |
| 399 |
| 369 } // namespace apps | 400 } // namespace apps |
| OLD | NEW |