Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: chrome/browser/chromeos/volume_bubble.cc

Issue 2790012: Volume bubble added for ChromeOS. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/volume_bubble.h ('k') | chrome/browser/chromeos/volume_bubble_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/volume_bubble.cc
===================================================================
--- chrome/browser/chromeos/volume_bubble.cc (revision 0)
+++ chrome/browser/chromeos/volume_bubble.cc (revision 0)
@@ -0,0 +1,107 @@
+// 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/chromeos/volume_bubble.h"
+
+#include <gdk/gdk.h>
+
+#include "base/timer.h"
+#include "chrome/browser/chromeos/volume_bubble_view.h"
+#include "chrome/browser/views/info_bubble.h"
+#include "views/widget/root_view.h"
+
+namespace {
+const int kBubbleShowTimeoutSec = 2;
+const int kAnimationDurationMs = 200;
+const int kVolumeBubbleX = 300, kVolumeBubbleY = 700;
+} // namespace
+
+namespace chromeos {
+
+// Temporary helper routine. Returns currently shown Chrome widget or NULL.
+// TODO(glotov): remove this in favor of enabling InfoBubble class act
+// without |parent| specified. crosbug.com/4025
+static views::Widget* GetToplevelWidget() {
+ views::Widget* widget = NULL;
+ GList *window_list = gtk_window_list_toplevels();
+ for (GList* iter = window_list; iter; iter = g_list_next(iter)) {
+ GtkWindow* const window = GTK_WINDOW(iter->data);
+ if (window && GTK_WIDGET(window)->window ==
+ gdk_screen_get_active_window(gdk_screen_get_default())) {
+ views::RootView* root = views::Widget::FindRootView(window);
+ if (root)
+ widget = root->GetWidget();
+ break;
+ }
+ }
+ g_list_free(window_list);
+ return widget;
+}
+
+VolumeBubble::VolumeBubble()
+ : previous_percent_(-1),
+ current_percent_(-1),
+ bubble_(NULL),
+ view_(NULL),
+ animation_(this) {
+ animation_.SetSlideDuration(kAnimationDurationMs);
+ animation_.SetTweenType(Tween::LINEAR);
+}
+
+void VolumeBubble::ShowVolumeBubble(int percent) {
+ if (percent < 0) percent = 0;
sky 2010/06/16 15:14:08 Please, no single line ifs.
glotov 2010/06/16 16:30:38 Done.
+ if (percent > 100) percent = 100;
+ if (previous_percent_ == -1) previous_percent_ = percent;
+ current_percent_ = percent;
+ if (!bubble_) {
+ views::Widget* widget = GetToplevelWidget();
+ if (widget == NULL)
+ return;
+ DCHECK(view_ == NULL);
+ view_ = new VolumeBubbleView;
+ view_->Init(previous_percent_);
+ // TODO(glotov): Place volume bubble over the keys initiated the
+ // volume change. This metric must be specific to the given
+ // architecture. crosbug.com/4028
+ bubble_ = InfoBubble::Show(widget,
+ gfx::Rect(kVolumeBubbleX, kVolumeBubbleY, 0, 0),
+ BubbleBorder::FLOAT, view_, this);
+ } else {
+ DCHECK(view_);
+ timeout_timer_.Stop();
+ }
+ if (animation_.is_animating()) animation_.End();
+ animation_.Reset();
+ animation_.Show();
+ timeout_timer_.Start(base::TimeDelta::FromSeconds(kBubbleShowTimeoutSec),
+ this, &VolumeBubble::OnTimeout);
+}
+
+void VolumeBubble::OnTimeout() {
+ if (bubble_)
+ bubble_->Close();
+}
+
+void VolumeBubble::InfoBubbleClosing(InfoBubble* info_bubble, bool) {
+ DCHECK(info_bubble == bubble_);
+ timeout_timer_.Stop();
+ animation_.Stop();
+ bubble_ = NULL;
+ view_ = NULL;
+}
+
+void VolumeBubble::AnimationEnded(const Animation* animation) {
+ previous_percent_ = current_percent_;
+}
+
+void VolumeBubble::AnimationProgressed(const Animation* animation) {
+ if (view_) {
+ view_->Update(
+ Tween::ValueBetween(animation->GetCurrentValue(),
+ previous_percent_,
+ current_percent_));
+ }
+}
+
+} // namespace chromeos
Property changes on: chrome/browser/chromeos/volume_bubble.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/chromeos/volume_bubble.h ('k') | chrome/browser/chromeos/volume_bubble_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698