Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: ui/views/bubble/bubble_frame_view.cc

Issue 15861012: Polish new dialog style layout and sizing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove long title example debugging code. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/views/examples/widget_example.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bubble/bubble_frame_view.h" 5 #include "ui/views/bubble/bubble_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/hit_test.h" 10 #include "ui/base/hit_test.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/path.h" 12 #include "ui/gfx/path.h"
13 #include "ui/gfx/screen.h" 13 #include "ui/gfx/screen.h"
14 #include "ui/views/bubble/bubble_border.h" 14 #include "ui/views/bubble/bubble_border.h"
15 #include "ui/views/controls/button/label_button.h" 15 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
17 #include "ui/views/window/client_view.h" 17 #include "ui/views/window/client_view.h"
18 18
19 namespace { 19 namespace {
20 20
21 // Insets, in pixels, for the title view, when it exists. 21 // Padding, in pixels, for the title view, when it exists.
22 const int kTitleTopInset = 19; 22 const int kTitleTopInset = 12;
23 const int kTitleLeftInset = 10; 23 const int kTitleLeftInset = 19;
24 const int kTitleBottomInset = 12;
24 25
25 // Get the |vertical| or horizontal screen overflow of the |window_bounds|. 26 // Get the |vertical| or horizontal screen overflow of the |window_bounds|.
26 int GetOffScreenLength(const gfx::Rect& monitor_bounds, 27 int GetOffScreenLength(const gfx::Rect& monitor_bounds,
27 const gfx::Rect& window_bounds, 28 const gfx::Rect& window_bounds,
28 bool vertical) { 29 bool vertical) {
29 if (monitor_bounds.IsEmpty() || monitor_bounds.Contains(window_bounds)) 30 if (monitor_bounds.IsEmpty() || monitor_bounds.Contains(window_bounds))
30 return 0; 31 return 0;
31 32
32 // window_bounds 33 // window_bounds
33 // +-------------------------------+ 34 // +-------------------------------+
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 116 }
116 117
117 void BubbleFrameView::ResetWindowControls() {} 118 void BubbleFrameView::ResetWindowControls() {}
118 119
119 void BubbleFrameView::UpdateWindowIcon() {} 120 void BubbleFrameView::UpdateWindowIcon() {}
120 121
121 void BubbleFrameView::UpdateWindowTitle() {} 122 void BubbleFrameView::UpdateWindowTitle() {}
122 123
123 gfx::Insets BubbleFrameView::GetInsets() const { 124 gfx::Insets BubbleFrameView::GetInsets() const {
124 gfx::Insets insets = content_margins_; 125 gfx::Insets insets = content_margins_;
125 insets += gfx::Insets( 126 const int title_height = title_->text().empty() ? 0 :
126 std::max(title_->text().empty() ? 0 : title_->height() + kTitleTopInset, 127 title_->GetPreferredSize().height() + kTitleTopInset + kTitleBottomInset;
127 close_->visible() ? close_->height() : 0), 128 const int close_height = close_->visible() ? close_->height() : 0;
128 0, 0, 0); 129 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0);
129 return insets; 130 return insets;
130 } 131 }
131 132
132 gfx::Size BubbleFrameView::GetPreferredSize() { 133 gfx::Size BubbleFrameView::GetPreferredSize() {
133 gfx::Size client_size(GetWidget()->client_view()->GetPreferredSize()); 134 const gfx::Size client(GetWidget()->client_view()->GetPreferredSize());
134 return GetUpdatedWindowBounds(gfx::Rect(), client_size, false).size(); 135 gfx::Size size(GetUpdatedWindowBounds(gfx::Rect(), client, false).size());
136 // Accommodate the width of the title bar elements.
137 int title_bar_width = GetInsets().width() + border()->GetInsets().width() +
138 kTitleLeftInset + title_->GetPreferredSize().width() +
139 close_->width() + 1;
140 if (titlebar_extra_view_ != NULL)
141 title_bar_width += titlebar_extra_view_->GetPreferredSize().width();
142 size.ClampToMin(gfx::Size(title_bar_width, 0));
143 return size;
135 } 144 }
136 145
137 void BubbleFrameView::Layout() { 146 void BubbleFrameView::Layout() {
138 gfx::Rect bounds = GetLocalBounds(); 147 gfx::Rect bounds(GetLocalBounds());
139 bounds.Inset(border()->GetInsets()); 148 bounds.Inset(border()->GetInsets());
140 // Small additional insets yield the desired 10px visual close button insets. 149 // Small additional insets yield the desired 10px visual close button insets.
141 bounds.Inset(0, 2, close_->width() + 1, 0); 150 bounds.Inset(0, 0, close_->width() + 1, 0);
142 close_->SetPosition(gfx::Point(bounds.right(), bounds.y())); 151 close_->SetPosition(gfx::Point(bounds.right(), bounds.y() + 2));
143 152
144 gfx::Rect title_bounds = bounds; 153 gfx::Rect title_bounds(bounds);
145 title_bounds.Inset(kTitleTopInset, kTitleLeftInset, 0, 0); 154 title_bounds.Inset(kTitleLeftInset, kTitleTopInset, 0, 0);
146 155 gfx::Size title_size(title_->GetPreferredSize());
147 title_bounds.set_size(title_->GetPreferredSize()); 156 const int title_width = std::max(0, close_->bounds().x() - title_bounds.x());
157 title_size.ClampToMax(gfx::Size(title_width, title_size.height()));
158 title_bounds.set_size(title_size);
148 title_->SetBoundsRect(title_bounds); 159 title_->SetBoundsRect(title_bounds);
149 160
150 if (titlebar_extra_view_) { 161 if (titlebar_extra_view_) {
151 const gfx::Size size = titlebar_extra_view_->GetPreferredSize(); 162 const int extra_width = close_->bounds().x() - title_->bounds().right();
163 gfx::Size size = titlebar_extra_view_->GetPreferredSize();
164 size.ClampToMax(gfx::Size(std::max(0, extra_width), size.height()));
152 gfx::Rect titlebar_extra_view_bounds( 165 gfx::Rect titlebar_extra_view_bounds(
153 bounds.right() - size.width(), 166 bounds.right() - size.width(),
154 title_bounds.y(), 167 title_bounds.y(),
155 size.width(), 168 size.width(),
156 title_bounds.height()); 169 title_bounds.height());
157 titlebar_extra_view_bounds.Subtract(title_bounds); 170 titlebar_extra_view_bounds.Subtract(title_bounds);
158 titlebar_extra_view_->SetBoundsRect(titlebar_extra_view_bounds); 171 titlebar_extra_view_->SetBoundsRect(titlebar_extra_view_bounds);
159 } 172 }
160 } 173 }
161 174
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble 297 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble
285 // window needs to be moved to the right and that means we need to move arrow 298 // window needs to be moved to the right and that means we need to move arrow
286 // to the left, and that means negative offset. 299 // to the left, and that means negative offset.
287 bubble_border_->set_arrow_offset( 300 bubble_border_->set_arrow_offset(
288 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); 301 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust);
289 if (offscreen_adjust) 302 if (offscreen_adjust)
290 SchedulePaint(); 303 SchedulePaint();
291 } 304 }
292 305
293 } // namespace views 306 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/examples/widget_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698