OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/app_list/search_box_view.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/image/image.h" |
| 11 #include "ui/views/background.h" |
| 12 #include "ui/views/border.h" |
| 13 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/textfield/textfield.h" |
| 15 |
| 16 namespace ash { |
| 17 |
| 18 namespace { |
| 19 |
| 20 const int kPadding = 9; |
| 21 |
| 22 // 0.5 white |
| 23 const SkColor kBorderColor = SkColorSetARGB(0x7F, 0xFF, 0xFF, 0xFF); |
| 24 |
| 25 // 0.2 white |
| 26 const SkColor kBackgroundColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF); |
| 27 |
| 28 // 0.9 white |
| 29 const SkColor kTextColor = SkColorSetARGB(0xE5, 0xFF, 0xFF, 0xFF); |
| 30 |
| 31 } // namespace |
| 32 |
| 33 SearchBoxView::SearchBoxView() { |
| 34 set_border(views::Border::CreateSolidBorder(1, kBorderColor)); |
| 35 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 36 |
| 37 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 38 |
| 39 white_search_ = new views::ImageView; |
| 40 white_search_->SetImage( |
| 41 *rb.GetImageNamed(IDR_AURA_WHITE_SEARCH).ToSkBitmap()); |
| 42 AddChildView(white_search_); |
| 43 |
| 44 search_box_ = new views::Textfield; |
| 45 search_box_->RemoveBorder(); |
| 46 search_box_->SetBackgroundColor(0); // Clear color. |
| 47 search_box_->SetTextColor(kTextColor); |
| 48 search_box_->SetFont(rb.GetFont(ResourceBundle::BaseFont).DeriveFont( |
| 49 2, gfx::Font::BOLD)); |
| 50 AddChildView(search_box_); |
| 51 } |
| 52 |
| 53 std::string SearchBoxView::search_text() const { |
| 54 return UTF16ToUTF8(search_box_->text()); |
| 55 } |
| 56 |
| 57 void SearchBoxView::Layout() { |
| 58 gfx::Rect rect(GetContentsBounds()); |
| 59 |
| 60 gfx::Size icon_size = white_search_->GetPreferredSize(); |
| 61 gfx::Rect icon_frame(rect); |
| 62 icon_frame.set_width(icon_size.width() + 2 * kPadding); |
| 63 white_search_->SetBoundsRect(icon_frame); |
| 64 |
| 65 gfx::Rect edit_frame(rect); |
| 66 edit_frame.set_x(icon_frame.right()); |
| 67 edit_frame.set_width(rect.width() - icon_frame.width() - kPadding); |
| 68 search_box_->SetBoundsRect(edit_frame); |
| 69 } |
| 70 |
| 71 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 72 const string16& new_contents) { |
| 73 } |
| 74 |
| 75 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 76 const views::KeyEvent& key_event) { |
| 77 return false; |
| 78 } |
| 79 |
| 80 } // namespace ash |
OLD | NEW |