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 "chrome/browser/ui/views/find_bar_view.h" | 5 #include "chrome/browser/ui/views/find_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 #include "ui/resources/grit/ui_resources.h" | 30 #include "ui/resources/grit/ui_resources.h" |
31 #include "ui/views/border.h" | 31 #include "ui/views/border.h" |
32 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" |
33 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
34 #include "ui/views/ime/input_method.h" | 34 #include "ui/views/ime/input_method.h" |
35 #include "ui/views/painter.h" | 35 #include "ui/views/painter.h" |
36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // The margins around the search field, match count label, and the close button. | 40 // The margins around the UI controls, derived from assets and design specs. |
41 const int kMarginLeftOfCloseButton = 3; | 41 const int kMarginLeftOfCloseButton = 3; |
Peter Kasting
2014/09/05 22:56:48
Nit: Should we collapse this and kMarginLeftOfMatc
msw
2014/09/05 23:46:55
That might be reasonable for follow-up, but I'm no
| |
42 const int kMarginRightOfCloseButton = 7; | 42 const int kMarginRightOfCloseButton = 7; |
43 const int kMarginLeftOfMatchCountLabel = 2; | 43 const int kMarginLeftOfMatchCountLabel = 3; |
44 const int kMarginRightOfMatchCountLabel = 1; | 44 const int kMarginRightOfMatchCountLabel = 1; |
45 const int kMarginLeftOfFindTextfield = 12; | 45 const int kMarginLeftOfFindTextfield = 12; |
46 const int kMarginAboveFindTextfield = 6; | |
Peter Kasting
2014/09/05 22:56:48
Nit: Maybe this and the next constant should just
msw
2014/09/05 23:46:55
Done. I'm not entirely sure that these values are
| |
47 const int kMarginBelowFindTextfield = 6; | |
46 | 48 |
47 // The margins around the match count label (We add extra space so that the | 49 // The margins around the match count label (We add extra space so that the |
48 // background highlight extends beyond just the text). | 50 // background highlight extends beyond just the text). |
49 const int kMatchCountExtraWidth = 9; | 51 const int kMatchCountExtraWidth = 9; |
50 | 52 |
51 // Minimum width for the match count label. | 53 // Minimum width for the match count label. |
52 const int kMatchCountMinWidth = 30; | 54 const int kMatchCountMinWidth = 30; |
53 | 55 |
54 // The text color for the match count label. | 56 // The text color for the match count label. |
55 const SkColor kTextColorMatchCount = SkColorSetRGB(178, 178, 178); | 57 const SkColor kTextColorMatchCount = SkColorSetRGB(178, 178, 178); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 sz.height()); | 313 sz.height()); |
312 | 314 |
313 // Then the label showing the match count number. | 315 // Then the label showing the match count number. |
314 sz = match_count_text_->GetPreferredSize(); | 316 sz = match_count_text_->GetPreferredSize(); |
315 // We extend the label bounds a bit to give the background highlighting a bit | 317 // We extend the label bounds a bit to give the background highlighting a bit |
316 // of breathing room (margins around the text). | 318 // of breathing room (margins around the text). |
317 sz.Enlarge(kMatchCountExtraWidth, 0); | 319 sz.Enlarge(kMatchCountExtraWidth, 0); |
318 sz.SetToMax(gfx::Size(kMatchCountMinWidth, 0)); | 320 sz.SetToMax(gfx::Size(kMatchCountMinWidth, 0)); |
319 int match_count_x = | 321 int match_count_x = |
320 find_previous_button_->x() - kMarginRightOfMatchCountLabel - sz.width(); | 322 find_previous_button_->x() - kMarginRightOfMatchCountLabel - sz.width(); |
321 int find_text_y = (height() - find_text_->GetPreferredSize().height()) / 2; | 323 int find_text_y = kMarginAboveFindTextfield; |
Peter Kasting
2014/09/05 22:56:49
Interesting, is it no longer possible to use the p
msw
2014/09/05 23:46:55
This approach is preferable to the current code fo
| |
322 match_count_text_->SetBounds(match_count_x, | 324 match_count_text_->SetBounds(match_count_x, |
323 find_text_y + find_text_->GetBaseline() - | 325 find_text_y + find_text_->GetBaseline() - |
324 match_count_text_->GetBaseline(), | 326 match_count_text_->GetBaseline(), |
325 sz.width(), sz.height()); | 327 sz.width(), sz.height()); |
326 | 328 |
327 // And whatever space is left in between, gets filled up by the find edit box. | 329 // Fill the remaining width and available height with the textfield. |
328 int find_text_width = std::max(0, match_count_x - | 330 int margin_a = kMarginLeftOfFindTextfield - views::Textfield::kTextPadding; |
329 kMarginLeftOfMatchCountLabel - kMarginLeftOfFindTextfield); | 331 int margin_b = kMarginLeftOfMatchCountLabel - views::Textfield::kTextPadding; |
Peter Kasting
2014/09/05 22:56:48
Nit: I'm not in love with "margin_a" and "margin_b
msw
2014/09/05 23:46:55
Done.
| |
330 find_text_->SetBounds(kMarginLeftOfFindTextfield, find_text_y, | 332 int find_text_width = std::max(0, match_count_x - margin_a - margin_b); |
331 find_text_width, find_text_->GetPreferredSize().height()); | 333 find_text_->SetBounds( |
334 margin_a, | |
335 find_text_y, | |
336 find_text_width, | |
337 height() - kMarginAboveFindTextfield - kMarginBelowFindTextfield); | |
332 | 338 |
333 // The focus forwarder view is a hidden view that should cover the area | 339 // The focus forwarder view is a hidden view that should cover the area |
334 // between the find text box and the find button so that when the user clicks | 340 // between the find text box and the find button so that when the user clicks |
335 // in that area we focus on the find text box. | 341 // in that area we focus on the find text box. |
336 int find_text_edge = find_text_->x() + find_text_->width(); | 342 int find_text_edge = find_text_->x() + find_text_->width(); |
337 focus_forwarder_view_->SetBounds( | 343 focus_forwarder_view_->SetBounds( |
338 find_text_edge, find_previous_button_->y(), | 344 find_text_edge, find_previous_button_->y(), |
339 find_previous_button_->x() - find_text_edge, | 345 find_previous_button_->x() - find_text_edge, |
340 find_previous_button_->height()); | 346 find_previous_button_->height()); |
341 } | 347 } |
342 | 348 |
343 gfx::Size FindBarView::GetPreferredSize() const { | 349 gfx::Size FindBarView::GetPreferredSize() const { |
344 gfx::Size prefsize = find_text_->GetPreferredSize(); | 350 gfx::Size prefsize = find_text_->GetPreferredSize(); |
345 prefsize.set_height(preferred_height_); | 351 prefsize.set_height(preferred_height_); |
346 | 352 |
347 // Add up all the preferred sizes and margins of the rest of the controls. | 353 // Add up all the preferred sizes and margins of the rest of the controls. |
348 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + | 354 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + |
349 kMarginLeftOfFindTextfield, | 355 kMarginLeftOfFindTextfield - |
356 2 * views::Textfield::kTextPadding, | |
350 0); | 357 0); |
351 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); | 358 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); |
352 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); | 359 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); |
353 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); | 360 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); |
354 return prefsize; | 361 return prefsize; |
355 } | 362 } |
356 | 363 |
357 //////////////////////////////////////////////////////////////////////////////// | 364 //////////////////////////////////////////////////////////////////////////////// |
358 // FindBarView, views::ButtonListener implementation: | 365 // FindBarView, views::ButtonListener implementation: |
359 | 366 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
492 | 499 |
493 void FindBarView::OnThemeChanged() { | 500 void FindBarView::OnThemeChanged() { |
494 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 501 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
495 if (GetThemeProvider()) { | 502 if (GetThemeProvider()) { |
496 close_button_->SetBackground( | 503 close_button_->SetBackground( |
497 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 504 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |
498 rb.GetImageSkiaNamed(IDR_CLOSE_1), | 505 rb.GetImageSkiaNamed(IDR_CLOSE_1), |
499 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 506 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
500 } | 507 } |
501 } | 508 } |
OLD | NEW |