| 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 "ui/views/window/dialog_frame_view.h" | |
| 6 | |
| 7 #include "grit/ui_resources.h" | |
| 8 #include "ui/base/hit_test.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/gfx/canvas.h" | |
| 11 #include "ui/gfx/font.h" | |
| 12 #include "ui/gfx/image/image.h" | |
| 13 #include "ui/gfx/insets.h" | |
| 14 #include "ui/views/background.h" | |
| 15 #include "ui/views/bubble/bubble_border.h" | |
| 16 #include "ui/views/controls/button/label_button.h" | |
| 17 #include "ui/views/controls/label.h" | |
| 18 #include "ui/views/widget/widget.h" | |
| 19 #include "ui/views/window/dialog_delegate.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // The base spacing value, multiples of which are used in various places. | |
| 24 const int kSpacing = 10; | |
| 25 | |
| 26 // static | |
| 27 const char kViewClassName[] = "ui/views/DialogFrameView"; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 namespace views { | |
| 32 | |
| 33 //////////////////////////////////////////////////////////////////////////////// | |
| 34 // DialogFrameView, public: | |
| 35 | |
| 36 DialogFrameView::DialogFrameView(const string16& title) | |
| 37 : title_(NULL), | |
| 38 close_(NULL) { | |
| 39 BubbleBorder* border = | |
| 40 new BubbleBorder(BubbleBorder::FLOAT, BubbleBorder::SMALL_SHADOW, | |
| 41 GetNativeTheme()->GetSystemColor( | |
| 42 ui::NativeTheme::kColorId_DialogBackground)); | |
| 43 set_border(border); | |
| 44 // Update the background, which relies on the border. | |
| 45 set_background(new BubbleBackground(border)); | |
| 46 | |
| 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 48 title_ = new Label(title, rb.GetFont(ui::ResourceBundle::MediumFont)); | |
| 49 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 50 AddChildView(title_); | |
| 51 | |
| 52 close_ = new LabelButton(this, string16()); | |
| 53 close_->SetImage(CustomButton::STATE_NORMAL, | |
| 54 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | |
| 55 close_->SetImage(CustomButton::STATE_HOVERED, | |
| 56 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); | |
| 57 close_->SetImage(CustomButton::STATE_PRESSED, | |
| 58 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); | |
| 59 close_->SetSize(close_->GetPreferredSize()); | |
| 60 close_->set_border(NULL); | |
| 61 AddChildView(close_); | |
| 62 | |
| 63 // Set the margins for the content view. | |
| 64 content_margins_ = gfx::Insets(2 * kSpacing + title_->font().GetHeight(), | |
| 65 2 * kSpacing, 2 * kSpacing, 2 * kSpacing); | |
| 66 } | |
| 67 | |
| 68 DialogFrameView::~DialogFrameView() { | |
| 69 } | |
| 70 | |
| 71 //////////////////////////////////////////////////////////////////////////////// | |
| 72 // DialogFrameView, NonClientFrameView: | |
| 73 | |
| 74 gfx::Rect DialogFrameView::GetBoundsForClientView() const { | |
| 75 gfx::Rect client_bounds = GetLocalBounds(); | |
| 76 client_bounds.Inset(GetClientInsets()); | |
| 77 return client_bounds; | |
| 78 } | |
| 79 | |
| 80 gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds( | |
| 81 const gfx::Rect& client_bounds) const { | |
| 82 gfx::Rect window_bounds = client_bounds; | |
| 83 window_bounds.Inset(-GetClientInsets()); | |
| 84 return window_bounds; | |
| 85 } | |
| 86 | |
| 87 int DialogFrameView::NonClientHitTest(const gfx::Point& point) { | |
| 88 if (close_->GetMirroredBounds().Contains(point)) | |
| 89 return HTCLOSE; | |
| 90 return point.y() < GetClientInsets().top() ? HTCAPTION : HTCLIENT; | |
| 91 } | |
| 92 | |
| 93 void DialogFrameView::GetWindowMask(const gfx::Size& size, | |
| 94 gfx::Path* window_mask) { | |
| 95 } | |
| 96 | |
| 97 void DialogFrameView::ResetWindowControls() { | |
| 98 } | |
| 99 | |
| 100 void DialogFrameView::UpdateWindowIcon() { | |
| 101 } | |
| 102 | |
| 103 void DialogFrameView::UpdateWindowTitle() { | |
| 104 } | |
| 105 | |
| 106 //////////////////////////////////////////////////////////////////////////////// | |
| 107 // DialogFrameView, View overrides: | |
| 108 | |
| 109 std::string DialogFrameView::GetClassName() const { | |
| 110 return kViewClassName; | |
| 111 } | |
| 112 | |
| 113 void DialogFrameView::Layout() { | |
| 114 gfx::Rect bounds = GetLocalBounds(); | |
| 115 bounds.Inset(border()->GetInsets()); | |
| 116 // Small additional insets yield the desired 10px visual close button insets. | |
| 117 bounds.Inset(0, 2, close_->width() + 1, 0); | |
| 118 close_->SetPosition(gfx::Point(bounds.right(), bounds.y())); | |
| 119 // Small additional insets yield the desired 20px visual title label insets. | |
| 120 bounds.Inset(2 * kSpacing - 1, kSpacing, 0, 0); | |
| 121 bounds.set_height(title_->font().GetHeight()); | |
| 122 title_->SetBoundsRect(bounds); | |
| 123 } | |
| 124 | |
| 125 //////////////////////////////////////////////////////////////////////////////// | |
| 126 // DialogFrameView, ButtonListener overrides: | |
| 127 | |
| 128 void DialogFrameView::ButtonPressed(Button* sender, const ui::Event& event) { | |
| 129 if (sender == close_) | |
| 130 GetWidget()->Close(); | |
| 131 } | |
| 132 | |
| 133 //////////////////////////////////////////////////////////////////////////////// | |
| 134 // DialogFrameView, private: | |
| 135 | |
| 136 gfx::Insets DialogFrameView::GetClientInsets() const { | |
| 137 gfx::Insets insets = border()->GetInsets(); | |
| 138 insets += content_margins_; | |
| 139 return insets; | |
| 140 } | |
| 141 | |
| 142 } // namespace views | |
| OLD | NEW |