Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/find_bar_view.h" | 5 #include "chrome/browser/views/find_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/find_bar_controller.h" | 14 #include "chrome/browser/find_bar_controller.h" |
| 15 #include "chrome/browser/find_bar_state.h" | 15 #include "chrome/browser/find_bar_state.h" |
| 16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" | 17 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 #include "chrome/browser/themes/browser_theme_provider.h" | 18 #include "chrome/browser/themes/browser_theme_provider.h" |
| 19 #include "chrome/browser/view_ids.h" | 19 #include "chrome/browser/view_ids.h" |
| 20 #include "chrome/browser/views/find_bar_host.h" | 20 #include "chrome/browser/views/find_bar_host.h" |
| 21 #include "chrome/browser/views/frame/browser_view.h" | 21 #include "chrome/browser/views/frame/browser_view.h" |
| 22 #include "gfx/canvas.h" | 22 #include "gfx/canvas.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "third_party/skia/include/effects/SkGradientShader.h" | 25 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 26 #include "views/background.h" | 26 #include "views/background.h" |
| 27 #include "views/controls/button/image_button.h" | 27 #include "views/controls/button/image_button.h" |
| 28 #include "views/controls/label.h" | 28 #include "views/controls/label.h" |
| 29 #include "views/focus/focus_manager.h" | |
| 29 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
| 30 | 31 |
| 31 // The amount of whitespace to have before the find button. | 32 // The amount of whitespace to have before the find button. |
| 32 static const int kWhiteSpaceAfterMatchCountLabel = 1; | 33 static const int kWhiteSpaceAfterMatchCountLabel = 1; |
| 33 | 34 |
| 34 // The margins around the search field and the close button. | 35 // The margins around the search field and the close button. |
| 35 static const int kMarginLeftOfCloseButton = 3; | 36 static const int kMarginLeftOfCloseButton = 3; |
| 36 static const int kMarginRightOfCloseButton = 7; | 37 static const int kMarginRightOfCloseButton = 7; |
| 37 static const int kMarginLeftOfFindTextfield = 12; | 38 static const int kMarginLeftOfFindTextfield = 12; |
| 38 | 39 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 } | 217 } |
| 217 | 218 |
| 218 // The match_count label may have increased/decreased in size so we need to | 219 // The match_count label may have increased/decreased in size so we need to |
| 219 // do a layout and repaint the dialog so that the find text field doesn't | 220 // do a layout and repaint the dialog so that the find text field doesn't |
| 220 // partially overlap the match-count label when it increases on no matches. | 221 // partially overlap the match-count label when it increases on no matches. |
| 221 Layout(); | 222 Layout(); |
| 222 SchedulePaint(); | 223 SchedulePaint(); |
| 223 } | 224 } |
| 224 | 225 |
| 225 void FindBarView::SetFocusAndSelection(bool select_all) { | 226 void FindBarView::SetFocusAndSelection(bool select_all) { |
| 227 #if defined(OS_CHROMEOS) | |
| 228 // TODO(altimofeev): this workaround is needed only when the FindBar was | |
| 229 // opened from the wrench menu (it also works in the accelerator case, but it | |
| 230 // is not really needed). | |
| 231 | |
| 232 // Restore focus to allow the find bar's external focus tracker save the view | |
|
Finnur
2010/11/16 17:08:28
nit: save -> to save.
altimofeev
2010/11/17 09:58:11
Done.
| |
| 233 // that should be activated later (the tracker is created after the wrench | |
| 234 // menu has got the focus). | |
|
Finnur
2010/11/16 17:08:28
nit: got -> gotten. You can also use 'received'.
altimofeev
2010/11/17 09:58:11
I have settled on 'received'.
| |
| 235 find_text_->GetFocusManager()->RestoreFocusedView(); | |
| 236 // Request focus for the textfield. | |
|
Finnur
2010/11/16 17:08:28
nit: this comment is redundant.
altimofeev
2010/11/17 09:58:11
Done.
| |
| 237 find_text_->RequestFocus(); | |
| 238 // Storing is needed here because the view that has focus before the wrench | |
| 239 // menu activation will get focus just after the wrench menu is closed. | |
| 240 // The FindBar has it's own focus tracker, so it will focus the correct view | |
| 241 // on close. | |
| 242 find_text_->GetFocusManager()->StoreFocusedView(); | |
| 243 // Request focus again since call to StoreFocusedView unfocuses the view. | |
|
Finnur
2010/11/16 17:08:28
nit: call -> the call.
altimofeev
2010/11/17 09:58:11
Done.
| |
| 244 #endif | |
| 226 find_text_->RequestFocus(); | 245 find_text_->RequestFocus(); |
| 227 if (select_all && !find_text_->text().empty()) | 246 if (select_all && !find_text_->text().empty()) |
| 228 find_text_->SelectAll(); | 247 find_text_->SelectAll(); |
| 229 } | 248 } |
| 230 | 249 |
| 231 /////////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////////// |
| 232 // FindBarView, views::View overrides: | 251 // FindBarView, views::View overrides: |
| 233 | 252 |
| 234 void FindBarView::Paint(gfx::Canvas* canvas) { | 253 void FindBarView::Paint(gfx::Canvas* canvas) { |
| 235 SkPaint paint; | 254 SkPaint paint; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 | 537 |
| 519 void FindBarView::OnThemeChanged() { | 538 void FindBarView::OnThemeChanged() { |
| 520 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 539 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 521 if (GetThemeProvider()) { | 540 if (GetThemeProvider()) { |
| 522 close_button_->SetBackground( | 541 close_button_->SetBackground( |
| 523 GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), | 542 GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), |
| 524 rb.GetBitmapNamed(IDR_CLOSE_BAR), | 543 rb.GetBitmapNamed(IDR_CLOSE_BAR), |
| 525 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); | 544 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); |
| 526 } | 545 } |
| 527 } | 546 } |
| OLD | NEW |