diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 13:22:19 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 13:22:19 +0000 |
commit | 378eba1a0a9b667759e27abbb1adfb38e55ffe9f (patch) | |
tree | 84572a8f0f0f1165d38864f666f9053b812586f6 /chrome | |
parent | 284e0d6e941b4a87f56cfd7cab70a69194e50cae (diff) | |
download | chromium_src-378eba1a0a9b667759e27abbb1adfb38e55ffe9f.zip chromium_src-378eba1a0a9b667759e27abbb1adfb38e55ffe9f.tar.gz chromium_src-378eba1a0a9b667759e27abbb1adfb38e55ffe9f.tar.bz2 |
Earlier we used to show a static image in this state, instead we now show the animation.
The images for each step of the animation are stored horizontally next to each other in a sprite image
and during the animation we just draw the same bitmap with the x origin moving around from one step
to another and wrapping around.
BUG=53598
TEST=manual, start speech recognition, speak something and wait for the animation to show up on screen.
Review URL: http://codereview.chromium.org/3417012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/theme/speech_input_mic_mask.png | bin | 4616 -> 4406 bytes | |||
-rw-r--r-- | chrome/app/theme/speech_input_processing.png | bin | 1422 -> 0 bytes | |||
-rw-r--r-- | chrome/app/theme/theme_resources.grd | 1 | ||||
-rw-r--r-- | chrome/browser/cocoa/speech_input_window_controller.mm | 9 | ||||
-rw-r--r-- | chrome/browser/speech/speech_input_bubble.cc | 38 | ||||
-rw-r--r-- | chrome/browser/speech/speech_input_bubble.h | 12 | ||||
-rw-r--r-- | chrome/browser/speech/speech_input_bubble_gtk.cc | 13 | ||||
-rw-r--r-- | chrome/browser/speech/speech_input_bubble_views.cc | 5 |
8 files changed, 63 insertions, 15 deletions
diff --git a/chrome/app/theme/speech_input_mic_mask.png b/chrome/app/theme/speech_input_mic_mask.png Binary files differindex 1805467..30ffd3e 100644 --- a/chrome/app/theme/speech_input_mic_mask.png +++ b/chrome/app/theme/speech_input_mic_mask.png diff --git a/chrome/app/theme/speech_input_processing.png b/chrome/app/theme/speech_input_processing.png Binary files differdeleted file mode 100644 index 0529e35..0000000 --- a/chrome/app/theme/speech_input_processing.png +++ /dev/null diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd index 148bf9a..2d08f82 100644 --- a/chrome/app/theme/theme_resources.grd +++ b/chrome/app/theme/theme_resources.grd @@ -426,7 +426,6 @@ <include name="IDR_SPEECH_INPUT_MIC_EMPTY" file="speech_input_mic_empty.png" type="BINDATA" /> <include name="IDR_SPEECH_INPUT_MIC_FULL" file="speech_input_mic_full.png" type="BINDATA" /> <include name="IDR_SPEECH_INPUT_MIC_MASK" file="speech_input_mic_mask.png" type="BINDATA" /> - <include name="IDR_SPEECH_INPUT_PROCESSING" file="speech_input_processing.png" type="BINDATA" /> <include name="IDR_SPEECH_INPUT_SPINNER" file="speech_input_spinner.png" type="BINDATA" /> <if expr="pp_ifdef('_google_chrome')"> <include name="IDR_WIZARD_ICON" file="google_chrome/wizard_icon.png" type="BINDATA" /> diff --git a/chrome/browser/cocoa/speech_input_window_controller.mm b/chrome/browser/cocoa/speech_input_window_controller.mm index 6e8e862..1a9d165 100644 --- a/chrome/browser/cocoa/speech_input_window_controller.mm +++ b/chrome/browser/cocoa/speech_input_window_controller.mm @@ -149,10 +149,11 @@ const int kBubbleHorizontalMargin = 5; // Space on either sides of controls. } else { [instructionLabel_ setStringValue:l10n_util::GetNSString( IDS_SPEECH_INPUT_BUBBLE_HEADING)]; - NSImage* icon = ResourceBundle::GetSharedInstance().GetNSImageNamed( - (mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING ? - IDR_SPEECH_INPUT_MIC_EMPTY : IDR_SPEECH_INPUT_PROCESSING)); - [iconImage_ setImage:icon]; + if (mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING) { + NSImage* icon = ResourceBundle::GetSharedInstance().GetNSImageNamed( + IDR_SPEECH_INPUT_MIC_EMPTY); + [iconImage_ setImage:icon]; + } [iconImage_ setHidden:NO]; [iconImage_ setNeedsDisplay:YES]; [tryAgainButton_ setHidden:YES]; diff --git a/chrome/browser/speech/speech_input_bubble.cc b/chrome/browser/speech/speech_input_bubble.cc index be5d7c9..e84f29f 100644 --- a/chrome/browser/speech/speech_input_bubble.cc +++ b/chrome/browser/speech/speech_input_bubble.cc @@ -16,6 +16,8 @@ const int SpeechInputBubble::kBubbleTargetOffsetX = 5; SkBitmap* SpeechInputBubbleBase::mic_empty_ = NULL; SkBitmap* SpeechInputBubbleBase::mic_full_ = NULL; SkBitmap* SpeechInputBubbleBase::mic_mask_ = NULL; +SkBitmap* SpeechInputBubbleBase::spinner_ = NULL; +const int SpeechInputBubbleBase::kRecognizingAnimationStepMs = 100; SpeechInputBubble* SpeechInputBubble::Create(TabContents* tab_contents, Delegate* delegate, @@ -31,7 +33,8 @@ SpeechInputBubble* SpeechInputBubble::Create(TabContents* tab_contents, } SpeechInputBubbleBase::SpeechInputBubbleBase() - : display_mode_(DISPLAY_MODE_RECORDING) { + : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), + display_mode_(DISPLAY_MODE_RECORDING) { if (!mic_empty_) { // Static variables. mic_empty_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_SPEECH_INPUT_MIC_EMPTY); @@ -39,6 +42,8 @@ SpeechInputBubbleBase::SpeechInputBubbleBase() IDR_SPEECH_INPUT_MIC_FULL); mic_mask_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_SPEECH_INPUT_MIC_MASK); + spinner_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_SPEECH_INPUT_SPINNER); } // Instance variables. @@ -51,6 +56,17 @@ SpeechInputBubbleBase::SpeechInputBubbleBase() buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, mic_empty_->width(), mic_empty_->height()); buffer_image_->allocPixels(); + + // The sprite image consists of all the animation frames put together in one + // horizontal/wide image. Each animation frame is square in shape within the + // sprite. + int frame_size = spinner_->height(); + for (int x = 0; x < spinner_->width(); x += frame_size) { + SkBitmap frame; + spinner_->extractSubset(&frame, + SkIRect::MakeXYWH(x, 0, frame_size, frame_size)); + animation_frames_.push_back(frame); + } } SpeechInputBubbleBase::~SpeechInputBubbleBase() { @@ -60,6 +76,7 @@ SpeechInputBubbleBase::~SpeechInputBubbleBase() { } void SpeechInputBubbleBase::SetRecordingMode() { + task_factory_.RevokeAll(); display_mode_ = DISPLAY_MODE_RECORDING; UpdateLayout(); } @@ -67,9 +84,28 @@ void SpeechInputBubbleBase::SetRecordingMode() { void SpeechInputBubbleBase::SetRecognizingMode() { display_mode_ = DISPLAY_MODE_RECOGNIZING; UpdateLayout(); + + animation_step_ = 0; + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + task_factory_.NewRunnableMethod( + &SpeechInputBubbleBase::DoRecognizingAnimationStep), + kRecognizingAnimationStepMs); +} + +void SpeechInputBubbleBase::DoRecognizingAnimationStep() { + SetImage(animation_frames_[animation_step_]); + if (++animation_step_ >= animation_frames_.size()) + animation_step_ = 0; + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + task_factory_.NewRunnableMethod( + &SpeechInputBubbleBase::DoRecognizingAnimationStep), + kRecognizingAnimationStepMs); } void SpeechInputBubbleBase::SetMessage(const string16& text) { + task_factory_.RevokeAll(); message_text_ = text; display_mode_ = DISPLAY_MODE_MESSAGE; UpdateLayout(); diff --git a/chrome/browser/speech/speech_input_bubble.h b/chrome/browser/speech/speech_input_bubble.h index 73032b5..3faabe0 100644 --- a/chrome/browser/speech/speech_input_bubble.h +++ b/chrome/browser/speech/speech_input_bubble.h @@ -6,8 +6,11 @@ #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ #pragma once +#include <vector> + #include "base/scoped_ptr.h" #include "base/string16.h" +#include "base/task.h" namespace gfx { class Rect; @@ -143,6 +146,13 @@ class SpeechInputBubbleBase : public SpeechInputBubble { } private: + void DoRecognizingAnimationStep(); + + // Task factory used for animation timer. + ScopedRunnableMethodFactory<SpeechInputBubbleBase> task_factory_; + int animation_step_; // Current index/step of the animation. + std::vector<SkBitmap> animation_frames_; + DisplayMode display_mode_; string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE // The current microphone image with volume level indication. @@ -153,6 +163,8 @@ class SpeechInputBubbleBase : public SpeechInputBubble { static SkBitmap* mic_full_; // Mic image with full volume. static SkBitmap* mic_empty_; // Mic image with zero volume. static SkBitmap* mic_mask_; // Gradient mask used by the volume indicator. + static SkBitmap* spinner_; // Spinner image for the progress animation. + static const int kRecognizingAnimationStepMs; }; // This typedef is to workaround the issue with certain versions of diff --git a/chrome/browser/speech/speech_input_bubble_gtk.cc b/chrome/browser/speech/speech_input_bubble_gtk.cc index dc77b5b..55edac3 100644 --- a/chrome/browser/speech/speech_input_bubble_gtk.cc +++ b/chrome/browser/speech/speech_input_bubble_gtk.cc @@ -181,12 +181,13 @@ void SpeechInputBubbleGtk::UpdateLayout() { // button. gtk_label_set_text(GTK_LABEL(label_), l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_BUBBLE_HEADING).c_str()); - SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed( - display_mode() == DISPLAY_MODE_RECORDING ? IDR_SPEECH_INPUT_MIC_EMPTY : - IDR_SPEECH_INPUT_PROCESSING); - GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); - gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); - g_object_unref(pixbuf); + if (display_mode() == DISPLAY_MODE_RECORDING) { + SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_SPEECH_INPUT_MIC_EMPTY); + GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image); + gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); + g_object_unref(pixbuf); + } gtk_widget_show(icon_); gtk_widget_hide(try_again_button_); } diff --git a/chrome/browser/speech/speech_input_bubble_views.cc b/chrome/browser/speech/speech_input_bubble_views.cc index d41c79b..7e26fd5 100644 --- a/chrome/browser/speech/speech_input_bubble_views.cc +++ b/chrome/browser/speech/speech_input_bubble_views.cc @@ -102,10 +102,9 @@ void ContentView::UpdateLayout(SpeechInputBubbleBase::DisplayMode mode, if (mode == SpeechInputBubbleBase::DISPLAY_MODE_MESSAGE) { message_->SetText(UTF16ToWideHack(message_text)); - } else { + } else if (mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING) { icon_->SetImage(*ResourceBundle::GetSharedInstance().GetBitmapNamed( - (mode == SpeechInputBubbleBase::DISPLAY_MODE_RECORDING) ? - IDR_SPEECH_INPUT_MIC_EMPTY : IDR_SPEECH_INPUT_PROCESSING)); + IDR_SPEECH_INPUT_MIC_EMPTY)); } } |