OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/dialog_frame_view.h" |
| 6 |
| 7 #include "ui/gfx/canvas.h" |
| 8 #include "ui/gfx/font.h" |
| 9 #include "ui/views/background.h" |
| 10 #include "ui/views/border.h" |
| 11 #include "ui/views/widget/widget.h" |
| 12 #include "ui/views/widget/widget_delegate.h" |
| 13 |
| 14 namespace ash { |
| 15 namespace internal { |
| 16 |
| 17 // static |
| 18 const char DialogFrameView::kViewClassName[] = "ash/wm/DialogFrameView"; |
| 19 |
| 20 // static |
| 21 gfx::Font* DialogFrameView::title_font_ = NULL; |
| 22 |
| 23 // TODO(benrg): tweak these values until they match kennedy-spec. |
| 24 // TODO(benrg): this may also mean tweaking the frame shadow opacity. |
| 25 const SkColor kDialogBackgroundColor = SK_ColorWHITE; |
| 26 const SkColor kDialogBorderColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); |
| 27 const SkColor kDialogTitleColor = SK_ColorBLACK; |
| 28 |
| 29 // TODO(benrg): Replace with width-based padding heuristic. |
| 30 static int kDialogPadding = 30; |
| 31 static int kDialogContentVSpacing = 18; |
| 32 |
| 33 const int kCloseButtonSize = 16; |
| 34 |
| 35 //////////////////////////////////////////////////////////////////////////////// |
| 36 // DialogFrameView, public: |
| 37 |
| 38 DialogFrameView::DialogFrameView() { |
| 39 set_background(views::Background::CreateSolidBackground( |
| 40 kDialogBackgroundColor)); |
| 41 set_border(views::Border::CreateSolidBorder(1, kDialogBorderColor)); |
| 42 if (!title_font_) |
| 43 title_font_ = new gfx::Font(gfx::Font().DeriveFont(4, gfx::Font::NORMAL)); |
| 44 } |
| 45 |
| 46 DialogFrameView::~DialogFrameView() { |
| 47 } |
| 48 |
| 49 //////////////////////////////////////////////////////////////////////////////// |
| 50 // DialogFrameView, views::NonClientFrameView: |
| 51 |
| 52 gfx::Rect DialogFrameView::GetBoundsForClientView() const { |
| 53 gfx::Rect client_bounds = GetLocalBounds(); |
| 54 client_bounds.Inset(kDialogPadding, GetNonClientTopHeight(), |
| 55 kDialogPadding, kDialogPadding); |
| 56 return client_bounds; |
| 57 } |
| 58 |
| 59 gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds( |
| 60 const gfx::Rect& client_bounds) const { |
| 61 gfx::Rect window_bounds = client_bounds; |
| 62 window_bounds.Inset(-kDialogPadding, -GetNonClientTopHeight(), |
| 63 -kDialogPadding, -kDialogPadding); |
| 64 return window_bounds; |
| 65 } |
| 66 |
| 67 int DialogFrameView::NonClientHitTest(const gfx::Point& point) { |
| 68 if (close_button_rect_.Contains(point)) |
| 69 return HTCLOSE; |
| 70 return point.y() < GetNonClientTopHeight() ? HTCAPTION : HTCLIENT; |
| 71 } |
| 72 |
| 73 void DialogFrameView::GetWindowMask(const gfx::Size& size, |
| 74 gfx::Path* window_mask) { |
| 75 // Nothing to do. |
| 76 } |
| 77 |
| 78 void DialogFrameView::ResetWindowControls() { |
| 79 // Nothing to do. |
| 80 } |
| 81 |
| 82 void DialogFrameView::UpdateWindowIcon() { |
| 83 // Nothing to do. |
| 84 } |
| 85 |
| 86 //////////////////////////////////////////////////////////////////////////////// |
| 87 // DialogFrameView, views::View overrides: |
| 88 |
| 89 std::string DialogFrameView::GetClassName() const { |
| 90 return kViewClassName; |
| 91 } |
| 92 |
| 93 void DialogFrameView::Layout() { |
| 94 title_display_rect_ = GetLocalBounds(); |
| 95 // TODO(benrg): size based on font height rather than bottom padding. |
| 96 close_button_rect_.SetRect(width() - kDialogPadding - kCloseButtonSize, |
| 97 kDialogPadding, kCloseButtonSize, |
| 98 kCloseButtonSize); |
| 99 title_display_rect_.Inset(kDialogPadding, kDialogPadding, |
| 100 kDialogPadding + kCloseButtonSize, kDialogPadding); |
| 101 title_display_rect_.set_height(title_font_->GetHeight()); |
| 102 } |
| 103 |
| 104 void DialogFrameView::OnPaint(gfx::Canvas* canvas) { |
| 105 views::View::OnPaint(canvas); |
| 106 canvas->FillRect(SK_ColorRED, close_button_rect_); |
| 107 views::WidgetDelegate* delegate = GetWidget()->widget_delegate(); |
| 108 if (!delegate) |
| 109 return; |
| 110 canvas->DrawStringInt(delegate->GetWindowTitle(), *title_font_, |
| 111 kDialogTitleColor, title_display_rect_); |
| 112 } |
| 113 |
| 114 // TODO(benrg): You may want to use a views::Button for the close box instead. |
| 115 bool DialogFrameView::OnMousePressed(const views::MouseEvent& event) { |
| 116 if (close_button_rect_.Contains(event.location())) |
| 117 return true; |
| 118 return View::OnMousePressed(event); |
| 119 } |
| 120 void DialogFrameView::OnMouseReleased(const views::MouseEvent& event) { |
| 121 if (close_button_rect_.Contains(event.location())) |
| 122 GetWidget()->Close(); |
| 123 } |
| 124 |
| 125 //////////////////////////////////////////////////////////////////////////////// |
| 126 // DialogFrameView, private: |
| 127 |
| 128 int DialogFrameView::GetNonClientTopHeight() const { |
| 129 return kDialogPadding + title_font_->GetHeight() + kDialogContentVSpacing; |
| 130 } |
| 131 |
| 132 } // namespace internal |
| 133 } // namespace views |
OLD | NEW |