| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 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 int find_text_y = kMarginVerticalFindTextfield; |
| 322 match_count_text_->SetBounds(match_count_x, | 323 match_count_text_->SetBounds(match_count_x, |
| 323 find_text_y + find_text_->GetBaseline() - | 324 find_text_y + find_text_->GetBaseline() - |
| 324 match_count_text_->GetBaseline(), | 325 match_count_text_->GetBaseline(), |
| 325 sz.width(), sz.height()); | 326 sz.width(), sz.height()); |
| 326 | 327 |
| 327 // And whatever space is left in between, gets filled up by the find edit box. | 328 // Fill the remaining width and available height with the textfield. |
| 328 int find_text_width = std::max(0, match_count_x - | 329 int left_margin = kMarginLeftOfFindTextfield - views::Textfield::kTextPadding; |
| 329 kMarginLeftOfMatchCountLabel - kMarginLeftOfFindTextfield); | 330 int find_text_width = std::max(0, match_count_x - left_margin - |
| 330 find_text_->SetBounds(kMarginLeftOfFindTextfield, find_text_y, | 331 kMarginLeftOfMatchCountLabel - views::Textfield::kTextPadding); |
| 331 find_text_width, find_text_->GetPreferredSize().height()); | 332 find_text_->SetBounds(left_margin, find_text_y, find_text_width, |
| 333 height() - 2 * kMarginVerticalFindTextfield); |
| 332 | 334 |
| 333 // The focus forwarder view is a hidden view that should cover the area | 335 // 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 | 336 // 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. | 337 // in that area we focus on the find text box. |
| 336 int find_text_edge = find_text_->x() + find_text_->width(); | 338 int find_text_edge = find_text_->x() + find_text_->width(); |
| 337 focus_forwarder_view_->SetBounds( | 339 focus_forwarder_view_->SetBounds( |
| 338 find_text_edge, find_previous_button_->y(), | 340 find_text_edge, find_previous_button_->y(), |
| 339 find_previous_button_->x() - find_text_edge, | 341 find_previous_button_->x() - find_text_edge, |
| 340 find_previous_button_->height()); | 342 find_previous_button_->height()); |
| 341 } | 343 } |
| 342 | 344 |
| 343 gfx::Size FindBarView::GetPreferredSize() const { | 345 gfx::Size FindBarView::GetPreferredSize() const { |
| 344 gfx::Size prefsize = find_text_->GetPreferredSize(); | 346 gfx::Size prefsize = find_text_->GetPreferredSize(); |
| 345 prefsize.set_height(preferred_height_); | 347 prefsize.set_height(preferred_height_); |
| 346 | 348 |
| 347 // Add up all the preferred sizes and margins of the rest of the controls. | 349 // Add up all the preferred sizes and margins of the rest of the controls. |
| 348 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + | 350 prefsize.Enlarge(kMarginLeftOfCloseButton + kMarginRightOfCloseButton + |
| 349 kMarginLeftOfFindTextfield, | 351 kMarginLeftOfFindTextfield - |
| 352 2 * views::Textfield::kTextPadding, |
| 350 0); | 353 0); |
| 351 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); | 354 prefsize.Enlarge(find_previous_button_->GetPreferredSize().width(), 0); |
| 352 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); | 355 prefsize.Enlarge(find_next_button_->GetPreferredSize().width(), 0); |
| 353 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); | 356 prefsize.Enlarge(close_button_->GetPreferredSize().width(), 0); |
| 354 return prefsize; | 357 return prefsize; |
| 355 } | 358 } |
| 356 | 359 |
| 357 //////////////////////////////////////////////////////////////////////////////// | 360 //////////////////////////////////////////////////////////////////////////////// |
| 358 // FindBarView, views::ButtonListener implementation: | 361 // FindBarView, views::ButtonListener implementation: |
| 359 | 362 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 495 |
| 493 void FindBarView::OnThemeChanged() { | 496 void FindBarView::OnThemeChanged() { |
| 494 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 497 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 495 if (GetThemeProvider()) { | 498 if (GetThemeProvider()) { |
| 496 close_button_->SetBackground( | 499 close_button_->SetBackground( |
| 497 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), | 500 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TAB_TEXT), |
| 498 rb.GetImageSkiaNamed(IDR_CLOSE_1), | 501 rb.GetImageSkiaNamed(IDR_CLOSE_1), |
| 499 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); | 502 rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
| 500 } | 503 } |
| 501 } | 504 } |
| OLD | NEW |