| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/window/dialog_frame_view.h" | 5 #include "ui/views/window/dialog_frame_view.h" |
| 6 | 6 |
| 7 #include "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
| 8 #include "ui/base/hit_test.h" | 8 #include "ui/base/hit_test.h" |
| 9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Update the background, which relies on the border. | 44 // Update the background, which relies on the border. |
| 45 set_background(new BubbleBackground(border)); | 45 set_background(new BubbleBackground(border)); |
| 46 | 46 |
| 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 48 title_ = new Label(title, rb.GetFont(ui::ResourceBundle::MediumFont)); | 48 title_ = new Label(title, rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 49 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 49 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 50 AddChildView(title_); | 50 AddChildView(title_); |
| 51 | 51 |
| 52 close_ = new LabelButton(this, string16()); | 52 close_ = new LabelButton(this, string16()); |
| 53 close_->SetImage(CustomButton::STATE_NORMAL, | 53 close_->SetImage(CustomButton::STATE_NORMAL, |
| 54 *rb.GetImageNamed(IDR_CLOSE_BAR).ToImageSkia()); | 54 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
| 55 close_->SetImage(CustomButton::STATE_HOVERED, | 55 close_->SetImage(CustomButton::STATE_HOVERED, |
| 56 *rb.GetImageNamed(IDR_CLOSE_BAR_H).ToImageSkia()); | 56 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
| 57 close_->SetImage(CustomButton::STATE_PRESSED, | 57 close_->SetImage(CustomButton::STATE_PRESSED, |
| 58 *rb.GetImageNamed(IDR_CLOSE_BAR_P).ToImageSkia()); | 58 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
| 59 close_->SetSize(close_->GetPreferredSize()); | 59 close_->SetSize(close_->GetPreferredSize()); |
| 60 close_->set_border(NULL); |
| 60 AddChildView(close_); | 61 AddChildView(close_); |
| 61 | 62 |
| 62 // Set the margins for the content view. | 63 // Set the margins for the content view. |
| 63 content_margins_ = gfx::Insets(2 * kSpacing + title_->font().GetHeight(), | 64 content_margins_ = gfx::Insets(2 * kSpacing + title_->font().GetHeight(), |
| 64 2 * kSpacing, 2 * kSpacing, 2 * kSpacing); | 65 2 * kSpacing, 2 * kSpacing, 2 * kSpacing); |
| 65 } | 66 } |
| 66 | 67 |
| 67 DialogFrameView::~DialogFrameView() { | 68 DialogFrameView::~DialogFrameView() { |
| 68 } | 69 } |
| 69 | 70 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
| 106 // DialogFrameView, View overrides: | 107 // DialogFrameView, View overrides: |
| 107 | 108 |
| 108 std::string DialogFrameView::GetClassName() const { | 109 std::string DialogFrameView::GetClassName() const { |
| 109 return kViewClassName; | 110 return kViewClassName; |
| 110 } | 111 } |
| 111 | 112 |
| 112 void DialogFrameView::Layout() { | 113 void DialogFrameView::Layout() { |
| 113 gfx::Rect bounds = GetLocalBounds(); | 114 gfx::Rect bounds = GetLocalBounds(); |
| 114 bounds.Inset(border()->GetInsets()); | 115 bounds.Inset(border()->GetInsets()); |
| 116 // Small additional insets yield the desired 10px visual close button insets. |
| 117 bounds.Inset(0, 2, 1, 0); |
| 115 close_->SetPosition(gfx::Point(bounds.right() - close_->width(), bounds.y())); | 118 close_->SetPosition(gfx::Point(bounds.right() - close_->width(), bounds.y())); |
| 116 bounds.Inset(gfx::Insets(kSpacing, 2 * kSpacing, 0, close_->width())); | 119 // Small additional insets yield the desired 20px visual title label insets. |
| 120 bounds.Inset(2 * kSpacing - 1, kSpacing, close_->width(), 0); |
| 117 bounds.set_height(title_->font().GetHeight()); | 121 bounds.set_height(title_->font().GetHeight()); |
| 118 title_->SetBoundsRect(bounds); | 122 title_->SetBoundsRect(bounds); |
| 119 } | 123 } |
| 120 | 124 |
| 121 //////////////////////////////////////////////////////////////////////////////// | 125 //////////////////////////////////////////////////////////////////////////////// |
| 122 // DialogFrameView, ButtonListener overrides: | 126 // DialogFrameView, ButtonListener overrides: |
| 123 | 127 |
| 124 void DialogFrameView::ButtonPressed(Button* sender, const ui::Event& event) { | 128 void DialogFrameView::ButtonPressed(Button* sender, const ui::Event& event) { |
| 125 if (sender == close_) | 129 if (sender == close_) |
| 126 GetWidget()->Close(); | 130 GetWidget()->Close(); |
| 127 } | 131 } |
| 128 | 132 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////////// |
| 130 // DialogFrameView, private: | 134 // DialogFrameView, private: |
| 131 | 135 |
| 132 gfx::Insets DialogFrameView::GetClientInsets() const { | 136 gfx::Insets DialogFrameView::GetClientInsets() const { |
| 133 gfx::Insets insets = border()->GetInsets(); | 137 gfx::Insets insets = border()->GetInsets(); |
| 134 insets += content_margins_; | 138 insets += content_margins_; |
| 135 return insets; | 139 return insets; |
| 136 } | 140 } |
| 137 | 141 |
| 138 } // namespace views | 142 } // namespace views |
| OLD | NEW |