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/speech/speech_recognition_bubble.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
14 #include "chrome/browser/ui/views/toolbar_view.h" | 14 #include "chrome/browser/ui/views/toolbar_view.h" |
15 #include "content/public/browser/resource_context.h" | 15 #include "content/public/browser/resource_context.h" |
16 #include "content/public/browser/speech_recognition_manager.h" | 16 #include "content/public/browser/speech_recognition_manager.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/views/bubble/bubble_delegate.h" | 23 #include "ui/views/bubble/bubble_delegate.h" |
24 #include "ui/views/controls/button/text_button.h" | 24 #include "ui/views/controls/button/label_button.h" |
25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
26 #include "ui/views/controls/label.h" | 26 #include "ui/views/controls/label.h" |
27 #include "ui/views/controls/link.h" | 27 #include "ui/views/controls/link.h" |
28 #include "ui/views/controls/link_listener.h" | 28 #include "ui/views/controls/link_listener.h" |
29 #include "ui/views/layout/layout_constants.h" | 29 #include "ui/views/layout/layout_constants.h" |
30 | 30 |
31 using content::WebContents; | 31 using content::WebContents; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const int kBubbleHorizMargin = 6; | 35 const int kBubbleHorizMargin = 6; |
36 const int kBubbleVertMargin = 4; | 36 const int kBubbleVertMargin = 4; |
37 const int kBubbleHeadingVertMargin = 6; | 37 const int kBubbleHeadingVertMargin = 6; |
38 const int kIconHorizontalOffset = 27; | 38 const int kIconHorizontalOffset = 27; |
39 const int kIconVerticalOffset = -7; | 39 const int kIconVerticalOffset = -7; |
40 | 40 |
41 // This is the SpeechRecognitionBubble content and views bubble delegate. | 41 // This is the SpeechRecognitionBubble content and views bubble delegate. |
42 class SpeechRecognitionBubbleView | 42 class SpeechRecognitionBubbleView : public views::BubbleDelegateView, |
43 : public views::BubbleDelegateView, | 43 public views::ButtonListener, |
44 public views::ButtonListener, | 44 public views::LinkListener { |
45 public views::LinkListener { | |
46 public: | 45 public: |
47 SpeechRecognitionBubbleView(SpeechRecognitionBubbleDelegate* delegate, | 46 SpeechRecognitionBubbleView(SpeechRecognitionBubbleDelegate* delegate, |
48 views::View* anchor_view, | 47 views::View* anchor_view, |
49 const gfx::Rect& element_rect, | 48 const gfx::Rect& element_rect, |
50 WebContents* web_contents); | 49 WebContents* web_contents); |
51 | 50 |
52 void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, | 51 void UpdateLayout(SpeechRecognitionBubbleBase::DisplayMode mode, |
53 const string16& message_text, | 52 const string16& message_text, |
54 const gfx::ImageSkia& image); | 53 const gfx::ImageSkia& image); |
55 void SetImage(const gfx::ImageSkia& image); | 54 void SetImage(const gfx::ImageSkia& image); |
(...skipping 20 matching lines...) Expand all Loading... |
76 } | 75 } |
77 | 76 |
78 private: | 77 private: |
79 SpeechRecognitionBubbleDelegate* delegate_; | 78 SpeechRecognitionBubbleDelegate* delegate_; |
80 gfx::Rect element_rect_; | 79 gfx::Rect element_rect_; |
81 WebContents* web_contents_; | 80 WebContents* web_contents_; |
82 bool notify_delegate_on_activation_change_; | 81 bool notify_delegate_on_activation_change_; |
83 views::ImageView* icon_; | 82 views::ImageView* icon_; |
84 views::Label* heading_; | 83 views::Label* heading_; |
85 views::Label* message_; | 84 views::Label* message_; |
86 views::TextButton* try_again_; | 85 views::LabelButton* try_again_; |
87 views::TextButton* cancel_; | 86 views::LabelButton* cancel_; |
88 views::Link* mic_settings_; | 87 views::Link* mic_settings_; |
89 SpeechRecognitionBubbleBase::DisplayMode display_mode_; | 88 SpeechRecognitionBubbleBase::DisplayMode display_mode_; |
90 const int kIconLayoutMinWidth; | 89 const int kIconLayoutMinWidth; |
91 | 90 |
92 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleView); | 91 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleView); |
93 }; | 92 }; |
94 | 93 |
95 SpeechRecognitionBubbleView::SpeechRecognitionBubbleView( | 94 SpeechRecognitionBubbleView::SpeechRecognitionBubbleView( |
96 SpeechRecognitionBubbleDelegate* delegate, | 95 SpeechRecognitionBubbleDelegate* delegate, |
97 views::View* anchor_view, | 96 views::View* anchor_view, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 149 |
151 message_ = new views::Label(); | 150 message_ = new views::Label(); |
152 message_->SetFont(font); | 151 message_->SetFont(font); |
153 message_->SetMultiLine(true); | 152 message_->SetMultiLine(true); |
154 AddChildView(message_); | 153 AddChildView(message_); |
155 | 154 |
156 icon_ = new views::ImageView(); | 155 icon_ = new views::ImageView(); |
157 icon_->SetHorizontalAlignment(views::ImageView::CENTER); | 156 icon_->SetHorizontalAlignment(views::ImageView::CENTER); |
158 AddChildView(icon_); | 157 AddChildView(icon_); |
159 | 158 |
160 cancel_ = new views::NativeTextButton( | 159 cancel_ = new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); |
161 this, l10n_util::GetStringUTF16(IDS_CANCEL)); | 160 cancel_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
162 AddChildView(cancel_); | 161 AddChildView(cancel_); |
163 | 162 |
164 try_again_ = new views::NativeTextButton( | 163 try_again_ = new views::LabelButton( |
165 this, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_TRY_AGAIN)); | 164 this, l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_TRY_AGAIN)); |
| 165 try_again_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
166 AddChildView(try_again_); | 166 AddChildView(try_again_); |
167 | 167 |
168 mic_settings_ = new views::Link( | 168 mic_settings_ = new views::Link( |
169 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); | 169 l10n_util::GetStringUTF16(IDS_SPEECH_INPUT_MIC_SETTINGS)); |
170 mic_settings_->set_listener(this); | 170 mic_settings_->set_listener(this); |
171 AddChildView(mic_settings_); | 171 AddChildView(mic_settings_); |
172 } | 172 } |
173 | 173 |
174 void SpeechRecognitionBubbleView::UpdateLayout( | 174 void SpeechRecognitionBubbleView::UpdateLayout( |
175 SpeechRecognitionBubbleBase::DisplayMode mode, | 175 SpeechRecognitionBubbleBase::DisplayMode mode, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 401 } |
402 | 402 |
403 } // namespace | 403 } // namespace |
404 | 404 |
405 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( | 405 SpeechRecognitionBubble* SpeechRecognitionBubble::CreateNativeBubble( |
406 WebContents* web_contents, | 406 WebContents* web_contents, |
407 SpeechRecognitionBubble::Delegate* delegate, | 407 SpeechRecognitionBubble::Delegate* delegate, |
408 const gfx::Rect& element_rect) { | 408 const gfx::Rect& element_rect) { |
409 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); | 409 return new SpeechRecognitionBubbleImpl(web_contents, delegate, element_rect); |
410 } | 410 } |
OLD | NEW |