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; |
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 kMarginVerticalFindTextfield = 6; |
46 | 47 |
47 // The margins around the match count label (We add extra space so that the | 48 // The margins around the match count label (We add extra space so that the |
48 // background highlight extends beyond just the text). | 49 // background highlight extends beyond just the text). |
49 const int kMatchCountExtraWidth = 9; | 50 const int kMatchCountExtraWidth = 9; |
50 | 51 |
51 // Minimum width for the match count label. | 52 // Minimum width for the match count label. |
52 const int kMatchCountMinWidth = 30; | 53 const int kMatchCountMinWidth = 30; |
53 | 54 |
54 // The text color for the match count label. | 55 // The text color for the match count label. |
55 const SkColor kTextColorMatchCount = SkColorSetRGB(178, 178, 178); | 56 const SkColor kTextColorMatchCount = SkColorSetRGB(178, 178, 178); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 (height() - sz.height()) / 2, | 310 (height() - sz.height()) / 2, |
310 sz.width(), | 311 sz.width(), |
311 sz.height()); | 312 sz.height()); |
312 | 313 |
313 // Then the label showing the match count number. | 314 // Then the label showing the match count number. |
314 sz = match_count_text_->GetPreferredSize(); | 315 sz = match_count_text_->GetPreferredSize(); |
315 // We extend the label bounds a bit to give the background highlighting a bit | 316 // We extend the label bounds a bit to give the background highlighting a bit |
316 // of breathing room (margins around the text). | 317 // of breathing room (margins around the text). |
317 sz.Enlarge(kMatchCountExtraWidth, 0); | 318 sz.Enlarge(kMatchCountExtraWidth, 0); |
318 sz.SetToMax(gfx::Size(kMatchCountMinWidth, 0)); | 319 sz.SetToMax(gfx::Size(kMatchCountMinWidth, 0)); |
319 int match_count_x = | 320 const int match_count_x = |
320 find_previous_button_->x() - kMarginRightOfMatchCountLabel - sz.width(); | 321 find_previous_button_->x() - kMarginRightOfMatchCountLabel - sz.width(); |
321 int find_text_y = (height() - find_text_->GetPreferredSize().height()) / 2; | 322 const int find_text_y = kMarginVerticalFindTextfield; |
| 323 const gfx::Insets find_text_insets(find_text_->GetInsets()); |
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_insets.top() + |
| 326 find_text_->GetBaseline() - |
324 match_count_text_->GetBaseline(), | 327 match_count_text_->GetBaseline(), |
325 sz.width(), sz.height()); | 328 sz.width(), sz.height()); |
326 | 329 |
327 // And whatever space is left in between, gets filled up by the find edit box. | 330 // Fill the remaining width and available height with the textfield. |
328 int find_text_width = std::max(0, match_count_x - | 331 const int left_margin = kMarginLeftOfFindTextfield - find_text_insets.left(); |
329 kMarginLeftOfMatchCountLabel - kMarginLeftOfFindTextfield); | 332 const int find_text_width = std::max(0, match_count_x - left_margin - |
330 find_text_->SetBounds(kMarginLeftOfFindTextfield, find_text_y, | 333 kMarginLeftOfMatchCountLabel + find_text_insets.right()); |
331 find_text_width, find_text_->GetPreferredSize().height()); | 334 find_text_->SetBounds(left_margin, find_text_y, find_text_width, |
| 335 height() - 2 * kMarginVerticalFindTextfield); |
332 | 336 |
333 // The focus forwarder view is a hidden view that should cover the area | 337 // 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 | 338 // 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. | 339 // in that area we focus on the find text box. |
336 int find_text_edge = find_text_->x() + find_text_->width(); | 340 const int find_text_edge = find_text_->x() + find_text_->width(); |
337 focus_forwarder_view_->SetBounds( | 341 focus_forwarder_view_->SetBounds( |
338 find_text_edge, find_previous_button_->y(), | 342 find_text_edge, find_previous_button_->y(), |
339 find_previous_button_->x() - find_text_edge, | 343 find_previous_button_->x() - find_text_edge, |
340 find_previous_button_->height()); | 344 find_previous_button_->height()); |
341 } | 345 } |
342 | 346 |
343 gfx::Size FindBarView::GetPreferredSize() const { | 347 gfx::Size FindBarView::GetPreferredSize() const { |
344 gfx::Size prefsize = find_text_->GetPreferredSize(); | 348 gfx::Size prefsize = find_text_->GetPreferredSize(); |
345 prefsize.set_height(preferred_height_); | 349 prefsize.set_height(preferred_height_); |
346 | 350 |
347 // Add up all the preferred sizes and margins of the rest of the controls. | 351 // Add up all the preferred sizes and margins of the rest of the controls. |
348 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + | 352 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + |
349 kMarginLeftOfFindTextfield, | 353 kMarginLeftOfFindTextfield - |
| 354 find_text_->GetInsets().width(), |
350 0); | 355 0); |
351 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); | 356 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); |
352 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); | 357 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); |
353 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); | 358 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); |
354 return prefsize; | 359 return prefsize; |
355 } | 360 } |
356 | 361 |
357 //////////////////////////////////////////////////////////////////////////////// | 362 //////////////////////////////////////////////////////////////////////////////// |
358 // FindBarView, views::ButtonListener implementation: | 363 // FindBarView, views::ButtonListener implementation: |
359 | 364 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 497 |
493 void FindBarView::OnThemeChanged() { | 498 void FindBarView::OnThemeChanged() { |
494 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 499 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
495 if (GetThemeProvider()) { | 500 if (GetThemeProvider()) { |
496 close_button_->SetBackground( | 501 close_button_->SetBackground( |
497 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 502 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |
498 rb.GetImageSkiaNamed(IDR_CLOSE_1), | 503 rb.GetImageSkiaNamed(IDR_CLOSE_1), |
499 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 504 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
500 } | 505 } |
501 } | 506 } |
OLD | NEW |