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

Side by Side 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: Rebased. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/input_method/mode_indicator_delegate_view.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/wm/window_animations.h"
10 #include "ash/wm/window_util.h"
11 #include "base/logging.h"
12 #include "ui/views/bubble/bubble_delegate.h"
13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/fill_layout.h"
15
16 namespace chromeos {
17 namespace input_method {
18
19 namespace {
20 // Minimum size of inner contents in pixel.
21 // 43 is the designed size including the default margin (6 * 2).
22 const int kMinSize = 31;
23
24 // If the cursor bounds is lower than this margin in pixel, the mode
25 // indicator is shown above the cursor instead on bottom.
26 const int kSizeMargin = 75;
27
28 // After this duration in msec, the mode inicator will be fading out.
29 const int kShowingDuration = 500;
30 } // namespace
31
32
33 ModeIndicatorDelegateView::ModeIndicatorDelegateView(
34 const gfx::Rect& cursor_bounds,
35 const string16& label)
36 : cursor_bounds_(cursor_bounds),
37 label_view_(new views::Label(label)) {
38 set_use_focusless(true);
39 set_accept_events(false);
40 set_parent_window(
41 ash::Shell::GetContainer(
42 ash::wm::GetActiveWindow()->GetRootWindow(),
43 ash::internal::kShellWindowId_InputMethodContainer));
44 set_shadow(views::BubbleBorder::NO_SHADOW);
45
46 // This is a workaround for an issue of BubbleFrameView
47 // http://crbug.com/325009
48 // Without this workaround, the bounds of the inner contents is shifted
49 // lower than the expectation on offscreen handling (e.g. showing the
50 // bubble upper then the anchor).
51 //
52 // TODO(komatsu): Delete this workaround when the above issue is fixed.
53 const gfx::Rect screen_bounds =
54 ash::Shell::GetScreen()->GetDisplayMatching(cursor_bounds).work_area();
55 if (screen_bounds.bottom() - cursor_bounds.bottom() > kSizeMargin)
56 set_arrow(views::BubbleBorder::TOP_CENTER);
57 else
58 set_arrow(views::BubbleBorder::BOTTOM_CENTER);
59 }
60
61 ModeIndicatorDelegateView::~ModeIndicatorDelegateView() {}
62
63 void ModeIndicatorDelegateView::FadeOut() {
64 StartFade(false);
65 }
66
67 void ModeIndicatorDelegateView::ShowAndFadeOut() {
68 views::corewm::SetWindowVisibilityAnimationTransition(
69 GetWidget()->GetNativeView(),
70 views::corewm::ANIMATE_HIDE);
71 GetWidget()->Show();
72 timer_.Start(FROM_HERE,
73 base::TimeDelta::FromMilliseconds(kShowingDuration),
74 this,
75 &ModeIndicatorDelegateView::FadeOut);
76 }
77
78 gfx::Size ModeIndicatorDelegateView::GetPreferredSize() {
79 gfx::Size size = label_view_->GetPreferredSize();
80 size.SetToMax(gfx::Size(kMinSize, kMinSize));
81 return size;
82 }
83
84 void ModeIndicatorDelegateView::Init() {
85 SetLayoutManager(new views::FillLayout());
86 AddChildView(label_view_);
87
88 SetAnchorRect(cursor_bounds_);
89 }
90
91 } // namespace input_method
92 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698