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

Unified Diff: chrome/browser/chromeos/input_method/mode_indicator_delegate_view.cc

Issue 98703003: Mode Indicator using BubbleDelegateView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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
Index: chrome/browser/chromeos/input_method/mode_indicator_delegate_view.cc
diff --git a/chrome/browser/chromeos/input_method/mode_indicator_delegate_view.cc b/chrome/browser/chromeos/input_method/mode_indicator_delegate_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b0670978a9ffa327a1ce9152cfa620553aa7eea
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/mode_indicator_delegate_view.cc
@@ -0,0 +1,88 @@
+// Copyright 2013 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/input_method/mode_indicator_delegate_view.h"
+
+#include "ash/shell.h"
+#include "ash/wm/window_animations.h"
+#include "base/logging.h"
+#include "ui/views/bubble/bubble_delegate.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/fill_layout.h"
+
+namespace chromeos {
+namespace input_method {
+
+namespace {
+// Minimum size of inner contents in pixel.
+const int kMinSize = 43;
+
+// If the cursor bounds is lower than this margin in pixel, the mode
+// indicator is shown above the cursor instead on bottom.
+const int kSizeMargin = 75;
+
+// After this duration in msec, the mode inicator will be fading out.
+const int kShowingDuration = 500;
+} // namespace
+
+// Class overriding views::Label::GetPreferredSize().
+class ModeIndicatorLabel : public views::Label {
+ public:
+ explicit ModeIndicatorLabel(const string16& label)
+ : views::Label(label) {}
+
+ virtual ~ModeIndicatorLabel() {}
+
+ virtual gfx::Size GetPreferredSize() OVERRIDE {
Jun Mukai 2013/12/02 21:08:41 You don't have to inherit Label. Actually you can
Hiro Komatsu 2013/12/03 02:39:36 Done.
+ gfx::Size size = views::Label::GetPreferredSize();
+ size.SetToMax(gfx::Size(kMinSize, kMinSize));
+ return size;
+ }
+};
+
+
+ModeIndicatorDelegateView::ModeIndicatorDelegateView(
+ const gfx::Rect& cursor_bounds,
+ const string16& label)
+ : cursor_bounds_(cursor_bounds),
+ label_(label) {
+ set_use_focusless(true);
+ set_accept_events(false);
+ set_shadow(views::BubbleBorder::NO_SHADOW);
Jun Mukai 2013/12/02 21:08:41 should specify parent_window? Otherwise it will be
Hiro Komatsu 2013/12/03 02:39:36 Done.
+
+ const gfx::Rect screen_bounds =
+ ash::Shell::GetScreen()->GetDisplayMatching(cursor_bounds).work_area();
+ if (screen_bounds.bottom() - cursor_bounds.bottom() > kSizeMargin)
+ set_arrow(views::BubbleBorder::TOP_CENTER);
+ else
+ set_arrow(views::BubbleBorder::BOTTOM_CENTER);
Jun Mukai 2013/12/02 21:08:41 you don't have to do that. Bubble can take care of
Hiro Komatsu 2013/12/03 02:39:36 It seems a bug of BubbleFrameView. Till the bug i
+}
+
+ModeIndicatorDelegateView::~ModeIndicatorDelegateView() {}
+
+void ModeIndicatorDelegateView::FadeOut() {
+ StartFade(false);
+}
+
+void ModeIndicatorDelegateView::ShowAndFadeOut() {
+ views::corewm::SetWindowVisibilityAnimationTransition(
+ GetWidget()->GetNativeView(),
+ views::corewm::ANIMATE_HIDE);
+ GetWidget()->Show();
+ timer_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(kShowingDuration),
+ this,
+ &ModeIndicatorDelegateView::FadeOut);
+}
+
+void ModeIndicatorDelegateView::Init() {
+ SetLayoutManager(new views::FillLayout());
+ ModeIndicatorLabel* label_view = new ModeIndicatorLabel(label_);
+ AddChildView(label_view);
+
+ SetAnchorRect(cursor_bounds_);
+}
+
+} // namespace input_method
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698