Chromium Code Reviews| Index: chrome/browser/ui/views/app_list/app_list_dialog/app_list_dialog_non_client_view.cc |
| diff --git a/chrome/browser/ui/views/app_list/app_list_dialog/app_list_dialog_non_client_view.cc b/chrome/browser/ui/views/app_list/app_list_dialog/app_list_dialog_non_client_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5343f59d715a305e3c7140f3e12d1faac718d5db |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/app_list/app_list_dialog/app_list_dialog_non_client_view.cc |
| @@ -0,0 +1,143 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/app_list/app_list_dialog/app_list_dialog_non_client_view.h" |
| + |
| +#include "SkColor.h" |
|
tapted
2014/06/11 08:35:00
these should have a full path
sashab
2014/06/12 00:13:43
Weird. Done.
|
| +#include "SkPaint.h" |
| +#include "SkRect.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "grit/ui_resources.h" |
| +#include "ui/base/accelerators/accelerator.h" |
| +#include "ui/base/hit_test.h" |
| +#include "ui/base/resource/resource_bundle.h" |
| +#include "ui/events/event.h" |
| +#include "ui/events/event_constants.h" |
| +#include "ui/events/keycodes/keyboard_codes_posix.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/geometry/insets.h" |
| +#include "ui/gfx/geometry/point.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "ui/gfx/path.h" |
| +#include "ui/views/background.h" |
| +#include "ui/views/border.h" |
| +#include "ui/views/controls/button/custom_button.h" |
| +#include "ui/views/controls/button/label_button.h" |
| +#include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/view.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "ui/views/window/client_view.h" |
| + |
| +namespace { |
| + |
| +// Margin of the close button from the top right-hand corner of the dialog. |
| +const int kCloseButtonDialogMargin = 10; |
| + |
| +// The background for App List dialogs, which appears as a white rounded |
| +// rectangle with the given radius and the same size as the target view. |
| +class AppListOverlayBackground : public views::Background { |
| + public: |
| + explicit AppListOverlayBackground(int corner_radius) |
| + : corner_radius_(corner_radius) {} |
| + virtual ~AppListOverlayBackground() {} |
| + |
| + // Overridden from views::Background: |
| + virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
| + SkPaint paint; |
| + paint.setStyle(SkPaint::kFill_Style); |
| + paint.setColor(SK_ColorWHITE); |
| + canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); |
| + } |
| + |
| + private: |
| + const int corner_radius_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListOverlayBackground); |
| +}; |
| + |
| +} // namespace |
| + |
| +AppListDialogNonClientView::AppListDialogNonClientView() { |
| + // TODO(sashab): Using SupportsShadow() from app_list_view.cc, make this |
| + // 1px smaller on platforms that support shadows. |
| + const int kAppListOverlayBorderRadius = 3; |
| + set_background(new AppListOverlayBackground(kAppListOverlayBorderRadius)); |
| + |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + close_ = new views::LabelButton(this, base::string16()); |
| + close_->SetImage(views::CustomButton::STATE_NORMAL, |
| + *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
| + close_->SetImage(views::CustomButton::STATE_HOVERED, |
| + *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
| + close_->SetImage(views::CustomButton::STATE_PRESSED, |
| + *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
| + close_->SetBorder(views::Border::NullBorder()); |
| + AddChildView(close_); |
| +} |
| + |
| +AppListDialogNonClientView::~AppListDialogNonClientView() { |
| +} |
| + |
| +gfx::Rect AppListDialogNonClientView::GetBoundsForClientView() const { |
| + gfx::Rect client_bounds = GetLocalBounds(); |
| + client_bounds.Inset(gfx::Insets(views::kButtonVEdgeMarginNew, |
| + views::kButtonHEdgeMarginNew, |
| + views::kButtonVEdgeMarginNew, |
| + views::kButtonHEdgeMarginNew)); |
| + return client_bounds; |
| +} |
| + |
| +gfx::Rect AppListDialogNonClientView::GetWindowBoundsForClientBounds( |
| + const gfx::Rect& client_bounds) const { |
| + gfx::Size size(client_bounds.size()); |
| + size.Enlarge(views::kButtonHEdgeMarginNew * 2, |
| + views::kButtonVEdgeMarginNew * 2); |
| + return gfx::Rect(size); |
| +} |
| + |
| +int AppListDialogNonClientView::NonClientHitTest(const gfx::Point& point) { |
| + if (!bounds().Contains(point)) |
| + return HTNOWHERE; |
| + if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
| + return HTCLOSE; |
| + |
| + return GetWidget()->client_view()->NonClientHitTest(point); |
| +} |
| + |
| +void AppListDialogNonClientView::GetWindowMask(const gfx::Size& size, |
| + gfx::Path* window_mask) { |
| + SkRect rect = {0, 0, size.width(), size.height()}; |
| + window_mask->addRect(rect); |
| +} |
| + |
| +void AppListDialogNonClientView::ResetWindowControls() { |
| + // Re-bind the ESCAPE key to trigger selecting the close button. |
| + ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
| + close_->SetVisible(true); |
| + close_->AddAccelerator(escape); |
| +} |
| + |
| +void AppListDialogNonClientView::UpdateWindowIcon() { |
| +} |
| + |
| +void AppListDialogNonClientView::UpdateWindowTitle() { |
| +} |
| + |
| +void AppListDialogNonClientView::Layout() { |
| + // Place the close button in the top right-hand corner. |
| + close_->SetSize(close_->GetPreferredSize()); |
| + close_->SetPosition( |
| + gfx::Point(width() - close_->width() - kCloseButtonDialogMargin, |
| + kCloseButtonDialogMargin)); |
| + close_->Layout(); |
| +} |
| + |
| +void AppListDialogNonClientView::ButtonPressed(views::Button* sender, |
| + const ui::Event& event) { |
| + if (sender == close_) { |
| + GetWidget()->Close(); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |