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 to save the |
| 233 // view that should be activated later (the tracker is created after the |
| 234 // wrench menu has received the focus). |
| 235 find_text_->GetFocusManager()->RestoreFocusedView(); |
| 236 find_text_->RequestFocus(); |
| 237 // Storing is needed here because the view that has focus before the wrench |
| 238 // menu activation will get focus just after the wrench menu is closed. |
| 239 // The FindBar has it's own focus tracker, so it will focus the correct view |
| 240 // on close. |
| 241 find_text_->GetFocusManager()->StoreFocusedView(); |
| 242 // Request focus again since the call to StoreFocusedView unfocuses the view. |
| 243 #endif |
226 find_text_->RequestFocus(); | 244 find_text_->RequestFocus(); |
227 if (select_all && !find_text_->text().empty()) | 245 if (select_all && !find_text_->text().empty()) |
228 find_text_->SelectAll(); | 246 find_text_->SelectAll(); |
229 } | 247 } |
230 | 248 |
231 /////////////////////////////////////////////////////////////////////////////// | 249 /////////////////////////////////////////////////////////////////////////////// |
232 // FindBarView, views::View overrides: | 250 // FindBarView, views::View overrides: |
233 | 251 |
234 void FindBarView::Paint(gfx::Canvas* canvas) { | 252 void FindBarView::Paint(gfx::Canvas* canvas) { |
235 SkPaint paint; | 253 SkPaint paint; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 536 |
519 void FindBarView::OnThemeChanged() { | 537 void FindBarView::OnThemeChanged() { |
520 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 538 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
521 if (GetThemeProvider()) { | 539 if (GetThemeProvider()) { |
522 close_button_->SetBackground( | 540 close_button_->SetBackground( |
523 GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), | 541 GetThemeProvider()->GetColor(BrowserThemeProvider::COLOR_TAB_TEXT), |
524 rb.GetBitmapNamed(IDR_CLOSE_BAR), | 542 rb.GetBitmapNamed(IDR_CLOSE_BAR), |
525 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); | 543 rb.GetBitmapNamed(IDR_CLOSE_BAR_MASK)); |
526 } | 544 } |
527 } | 545 } |
OLD | NEW |