summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 23:46:21 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 23:46:21 +0000
commit953a74689b716265653045cf95bbcdee57104729 (patch)
tree033c06fd901aff91b65a5af19fefd0b0821b72c1
parent393cfa5706c10e80523ef751f3bdd88eb502c155 (diff)
downloadchromium_src-953a74689b716265653045cf95bbcdee57104729.zip
chromium_src-953a74689b716265653045cf95bbcdee57104729.tar.gz
chromium_src-953a74689b716265653045cf95bbcdee57104729.tar.bz2
Reverting as this breaks Chromium OS. Please fix and reland.
Revert 58095 - Implement the speech input bubble on linux/gtk. This is a popup which gets displayed below an <input> element when the user starts speech recognition on it. It displays a recognition status icon, an instruction label ('Speak now') at the top and a Cancel button at the bottom. The speech input module gets callbacks on user actions such as clicking Cancel or clicking any other window, and on both cases recognition stops and the bubble closes. As part of this CL I had to move a constant from the windows code to the class so it can be used in gtk and mac. TEST=manual, the code to invoke the bubble depends on another pending CL. BUG=53598 Review URL: http://codereview.chromium.org/3231009 TBR=satish@chromium.org Review URL: http://codereview.chromium.org/3263010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58100 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/speech/speech_input_bubble.cc6
-rw-r--r--chrome/browser/speech/speech_input_bubble.h4
-rw-r--r--chrome/browser/speech/speech_input_bubble_gtk.cc137
-rw-r--r--chrome/browser/speech/speech_input_bubble_mac.mm7
-rw-r--r--chrome/browser/speech/speech_input_bubble_win.cc2
-rw-r--r--chrome/chrome_browser.gypi3
6 files changed, 11 insertions, 148 deletions
diff --git a/chrome/browser/speech/speech_input_bubble.cc b/chrome/browser/speech/speech_input_bubble.cc
index 4e2a670..744e774 100644
--- a/chrome/browser/speech/speech_input_bubble.cc
+++ b/chrome/browser/speech/speech_input_bubble.cc
@@ -7,7 +7,6 @@
#include "gfx/rect.h"
SpeechInputBubble::FactoryMethod SpeechInputBubble::factory_ = NULL;
-const int SpeechInputBubble::kBubbleTargetOffsetX = 5;
SpeechInputBubble* SpeechInputBubble::Create(TabContents* tab_contents,
Delegate* delegate,
@@ -19,5 +18,10 @@ SpeechInputBubble* SpeechInputBubble::Create(TabContents* tab_contents,
if (!tab_contents)
return NULL;
+#if defined(OS_WIN) || defined(OS_MACOSX)
return CreateNativeBubble(tab_contents, delegate, element_rect);
+#else
+ // TODO(satish): Remove once Linux implementation is ready.
+ return NULL;
+#endif
}
diff --git a/chrome/browser/speech/speech_input_bubble.h b/chrome/browser/speech/speech_input_bubble.h
index d99289d..020459c 100644
--- a/chrome/browser/speech/speech_input_bubble.h
+++ b/chrome/browser/speech/speech_input_bubble.h
@@ -68,10 +68,6 @@ class SpeechInputBubble {
// Indicates to the user that recognition is in progress.
virtual void SetRecognizingMode() = 0;
- // The horizontal distance between the start of the html widget and the speech
- // bubble's arrow.
- static const int kBubbleTargetOffsetX;
-
private:
static FactoryMethod factory_;
};
diff --git a/chrome/browser/speech/speech_input_bubble_gtk.cc b/chrome/browser/speech/speech_input_bubble_gtk.cc
deleted file mode 100644
index fed513c..0000000
--- a/chrome/browser/speech/speech_input_bubble_gtk.cc
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/speech/speech_input_bubble.h"
-
-#include "app/l10n_util.h"
-#include "app/resource_bundle.h"
-#include "chrome/browser/gtk/gtk_theme_provider.h"
-#include "chrome/browser/gtk/info_bubble_gtk.h"
-#include "chrome/browser/gtk/owned_widget_gtk.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
-#include "gfx/gtk_util.h"
-#include "gfx/rect.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-
-namespace {
-
-const int kBubbleControlVerticalSpacing = 10;
-const int kBubbleControlHorizontalSpacing = 50;
-
-// Use black for text labels since the bubble has white background.
-const GdkColor kLabelTextColor = gfx::kGdkBlack;
-
-// Implementation of SpeechInputBubble for GTK. This shows a speech input
-// info bubble on screen.
-class SpeechInputBubbleGtk
- : public SpeechInputBubble,
- public InfoBubbleGtkDelegate {
- public:
- SpeechInputBubbleGtk(TabContents* tab_contents,
- Delegate* delegate,
- const gfx::Rect& element_rect);
- ~SpeechInputBubbleGtk();
-
- private:
- // InfoBubbleDelegate methods.
- virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble,
- bool closed_by_escape);
-
- // SpeechInputBubble methods.
- virtual void SetRecognizingMode();
-
- CHROMEGTK_CALLBACK_0(SpeechInputBubbleGtk, void, OnCancelClicked);
-
- Delegate* delegate_;
- InfoBubbleGtk* info_bubble_;
- GtkWidget* icon_;
- OwnedWidgetGtk content_;
-
- DISALLOW_COPY_AND_ASSIGN(SpeechInputBubbleGtk);
-};
-
-SpeechInputBubbleGtk::SpeechInputBubbleGtk(TabContents* tab_contents,
- Delegate* delegate,
- const gfx::Rect& element_rect)
- : delegate_(delegate) {
- // We use a vbox to arrange the 3 controls (label, image, button) vertically.
- // To get horizontal space around them we place this vbox with padding in a
- // GtkAlignment below.
- GtkWidget* vbox = gtk_vbox_new(FALSE, kBubbleControlVerticalSpacing);
-
- GtkWidget* heading_label = gtk_label_new(
- l10n_util::GetStringUTF8(IDS_SPEECH_INPUT_BUBBLE_HEADING).c_str());
- gtk_widget_modify_fg(heading_label, GTK_STATE_NORMAL, &kLabelTextColor);
- gtk_box_pack_start(GTK_BOX(vbox), heading_label, FALSE, FALSE, 0);
-
- SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_SPEECH_INPUT_RECORDING);
- GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image);
- icon_ = gtk_image_new_from_pixbuf(pixbuf);
- g_object_unref(pixbuf);
- gtk_box_pack_start(GTK_BOX(vbox), icon_, FALSE, FALSE, 0);
-
- GtkWidget* cancel_button = gtk_button_new_with_label(
- l10n_util::GetStringUTF8(IDS_CANCEL).c_str());
- gtk_box_pack_start(GTK_BOX(vbox), cancel_button, FALSE, FALSE, 0);
- g_signal_connect(cancel_button, "clicked",
- G_CALLBACK(&OnCancelClickedThunk), this);
-
- content_.Own(gtk_alignment_new(0, 0, 0, 0));
- gtk_alignment_set_padding(GTK_ALIGNMENT(content_.get()),
- kBubbleControlVerticalSpacing, kBubbleControlVerticalSpacing,
- kBubbleControlHorizontalSpacing, kBubbleControlHorizontalSpacing);
- gtk_container_add(GTK_CONTAINER(content_.get()), vbox);
-
- GtkThemeProvider* theme_provider = GtkThemeProvider::GetFrom(
- tab_contents->profile());
- gfx::Rect rect(element_rect.x() + kBubbleTargetOffsetX,
- element_rect.y() + element_rect.height(), 1, 1);
- info_bubble_ = InfoBubbleGtk::Show(tab_contents->GetNativeView(),
- &rect,
- content_.get(),
- InfoBubbleGtk::ARROW_LOCATION_TOP_LEFT,
- false, // match_system_theme
- true, // grab_input
- theme_provider,
- this);
-}
-
-SpeechInputBubbleGtk::~SpeechInputBubbleGtk() {
- // The |Close| call below invokes our |InfoBubbleClosing| method. Since we
- // were destroyed by the caller we don't need to call them back, hence set
- // the delegate to NULL here.
- delegate_ = NULL;
- content_.Destroy();
- info_bubble_->Close();
-}
-
-void SpeechInputBubbleGtk::InfoBubbleClosing(InfoBubbleGtk* info_bubble,
- bool closed_by_escape) {
- if (delegate_)
- delegate_->InfoBubbleClosed();
-}
-
-void SpeechInputBubbleGtk::OnCancelClicked(GtkWidget* widget) {
- delegate_->RecognitionCancelled();
-}
-
-void SpeechInputBubbleGtk::SetRecognizingMode() {
- SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed(
- IDR_SPEECH_INPUT_PROCESSING);
- GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(image);
- gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf);
- g_object_unref(pixbuf);
-}
-
-} // namespace
-
-SpeechInputBubble* SpeechInputBubble::CreateNativeBubble(
- TabContents* tab_contents,
- Delegate* delegate,
- const gfx::Rect& element_rect) {
- return new SpeechInputBubbleGtk(tab_contents, delegate, element_rect);
-}
-
diff --git a/chrome/browser/speech/speech_input_bubble_mac.mm b/chrome/browser/speech/speech_input_bubble_mac.mm
index 43a390a..77631a3 100644
--- a/chrome/browser/speech/speech_input_bubble_mac.mm
+++ b/chrome/browser/speech/speech_input_bubble_mac.mm
@@ -36,10 +36,9 @@ SpeechInputBubbleImpl::SpeechInputBubbleImpl(TabContents* tab_contents,
// input element rect.
gfx::NativeView view = tab_contents->view()->GetNativeView();
NSRect tab_bounds = [view bounds];
- NSPoint anchor = NSMakePoint(
- tab_bounds.origin.x + element_rect.x() + kBubbleTargetOffsetX,
- tab_bounds.origin.y + tab_bounds.size.height - element_rect.y() -
- element_rect.height());
+ NSPoint anchor = NSMakePoint(tab_bounds.origin.x + element_rect.x(),
+ tab_bounds.origin.y + tab_bounds.size.height -
+ element_rect.y() - element_rect.height());
anchor = [view convertPoint:anchor toView:nil];
anchor = [[view window] convertBaseToScreen:anchor];
diff --git a/chrome/browser/speech/speech_input_bubble_win.cc b/chrome/browser/speech/speech_input_bubble_win.cc
index f69b7fd..9e74eac 100644
--- a/chrome/browser/speech/speech_input_bubble_win.cc
+++ b/chrome/browser/speech/speech_input_bubble_win.cc
@@ -27,6 +27,8 @@
namespace {
+// The speech bubble's arrow is so many pixels from the left of html element.
+const int kBubbleTargetOffsetX = 5;
const int kBubbleHorizMargin = 40;
const int kBubbleVertMargin = 0;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 1101489..cc8af50 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2471,9 +2471,8 @@
'browser/speech/endpointer/energy_endpointer_params.h',
'browser/speech/speech_input_bubble.h',
'browser/speech/speech_input_bubble.cc',
- 'browser/speech/speech_input_bubble_gtk.cc',
- 'browser/speech/speech_input_bubble_mac.mm',
'browser/speech/speech_input_bubble_win.cc',
+ 'browser/speech/speech_input_bubble_mac.mm',
'browser/speech/speech_input_bubble_controller.cc',
'browser/speech/speech_input_bubble_controller.h',
'browser/speech/speech_input_dispatcher_host.cc',