summaryrefslogtreecommitdiffstats
path: root/chrome/browser/speech/speech_input_bubble_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/speech/speech_input_bubble_controller.cc')
-rw-r--r--chrome/browser/speech/speech_input_bubble_controller.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/chrome/browser/speech/speech_input_bubble_controller.cc b/chrome/browser/speech/speech_input_bubble_controller.cc
new file mode 100644
index 0000000..98bf620
--- /dev/null
+++ b/chrome/browser/speech/speech_input_bubble_controller.cc
@@ -0,0 +1,108 @@
+// 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_controller.h"
+
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_util.h"
+#include "gfx/rect.h"
+
+namespace speech_input {
+
+SpeechInputBubbleController::SpeechInputBubbleController(Delegate* delegate)
+ : delegate_(delegate) {
+}
+
+void SpeechInputBubbleController::CreateBubble(int caller_id,
+ int render_process_id,
+ int render_view_id,
+ const gfx::Rect& element_rect) {
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &SpeechInputBubbleController::CreateBubble,
+ caller_id, render_process_id, render_view_id,
+ element_rect));
+ return;
+ }
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ TabContents* tab_contents = tab_util::GetTabContentsByID(render_process_id,
+ render_view_id);
+
+ DCHECK(!bubble_.get());
+ bubble_.reset(SpeechInputBubble::Create(tab_contents, this, element_rect));
+ if (!bubble_.get()) // could be null if tab or display rect were invalid.
+ return;
+
+ current_bubble_caller_id_ = caller_id;
+}
+
+void SpeechInputBubbleController::CloseBubble(int caller_id) {
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(this, &SpeechInputBubbleController::CloseBubble,
+ caller_id));
+ return;
+ }
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ if (current_bubble_caller_id_ != caller_id)
+ return;
+
+ current_bubble_caller_id_ = 0;
+
+ DCHECK(bubble_.get());
+ bubble_.reset();
+}
+
+void SpeechInputBubbleController::SetBubbleToRecognizingMode(int caller_id) {
+ if (!ChromeThread::CurrentlyOn(ChromeThread::UI)) {
+ ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod(
+ this, &SpeechInputBubbleController::SetBubbleToRecognizingMode,
+ caller_id));
+ return;
+ }
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ if (current_bubble_caller_id_ != caller_id)
+ return;
+
+ DCHECK(bubble_.get());
+ bubble_->SetRecognizingMode();
+}
+
+void SpeechInputBubbleController::RecognitionCancelled() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &SpeechInputBubbleController::InvokeDelegateRecognitionCancelled,
+ current_bubble_caller_id_));
+ current_bubble_caller_id_ = 0;
+ bubble_.reset();
+}
+
+void SpeechInputBubbleController::InfoBubbleClosed() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this,
+ &SpeechInputBubbleController::InvokeDelegateFocusChanged,
+ current_bubble_caller_id_));
+ current_bubble_caller_id_ = 0;
+ bubble_.reset();
+}
+
+void SpeechInputBubbleController::InvokeDelegateRecognitionCancelled(
+ int caller_id) {
+ delegate_->RecognitionCancelled(caller_id);
+}
+
+void SpeechInputBubbleController::InvokeDelegateFocusChanged(int caller_id) {
+ delegate_->SpeechInputFocusChanged(caller_id);
+}
+
+} // namespace speech_input