1 // Copyright 2014 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.
5 #include "ash/ime/mode_indicator_view.h"
7 #include "base/logging.h"
8 #include "ui/views/bubble/bubble_delegate.h"
9 #include "ui/views/controls/label.h"
10 #include "ui/views/corewm/window_animations.h"
11 #include "ui/views/layout/fill_layout.h"
17 // Minimum size of inner contents in pixel.
18 // 43 is the designed size including the default margin (6 * 2).
19 const int kMinSize
= 31;
21 // After this duration in msec, the mode inicator will be fading out.
22 const int kShowingDuration
= 500;
26 ModeIndicatorView::ModeIndicatorView(gfx::NativeView parent
,
27 const gfx::Rect
& cursor_bounds
,
28 const base::string16
& label
)
29 : cursor_bounds_(cursor_bounds
),
30 label_view_(new views::Label(label
)) {
31 set_use_focusless(true);
32 set_accept_events(false);
33 set_parent_window(parent
);
34 set_shadow(views::BubbleBorder::NO_SHADOW
);
35 set_arrow(views::BubbleBorder::TOP_CENTER
);
38 ModeIndicatorView::~ModeIndicatorView() {}
40 void ModeIndicatorView::FadeOut() {
44 void ModeIndicatorView::ShowAndFadeOut() {
45 views::corewm::SetWindowVisibilityAnimationTransition(
46 GetWidget()->GetNativeView(),
47 views::corewm::ANIMATE_HIDE
);
49 timer_
.Start(FROM_HERE
,
50 base::TimeDelta::FromMilliseconds(kShowingDuration
),
52 &ModeIndicatorView::FadeOut
);
55 gfx::Size
ModeIndicatorView::GetPreferredSize() {
56 gfx::Size size
= label_view_
->GetPreferredSize();
57 size
.SetToMax(gfx::Size(kMinSize
, kMinSize
));
61 void ModeIndicatorView::Init() {
62 SetLayoutManager(new views::FillLayout());
63 AddChildView(label_view_
);
65 SetAnchorRect(cursor_bounds_
);