Update V8 to version 4.7.45.
[chromium-blink-merge.git] / ui / chromeos / ime / mode_indicator_view.cc
blob38e2f459c8f35ce84313808aa4bda41b49a5731c
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 "ui/chromeos/ime/mode_indicator_view.h"
7 #include "base/logging.h"
8 #include "ui/gfx/display.h"
9 #include "ui/gfx/screen.h"
10 #include "ui/views/bubble/bubble_delegate.h"
11 #include "ui/views/bubble/bubble_frame_view.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/layout/fill_layout.h"
14 #include "ui/wm/core/window_animations.h"
16 namespace ui {
17 namespace ime {
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;
24 // After this duration in msec, the mode inicator will be fading out.
25 const int kShowingDuration = 500;
27 class ModeIndicatorFrameView : public views::BubbleFrameView {
28 public:
29 explicit ModeIndicatorFrameView(const gfx::Insets& content_margins)
30 : views::BubbleFrameView(content_margins) {}
31 ~ModeIndicatorFrameView() override {}
33 private:
34 // views::BubbleFrameView overrides:
35 gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override {
36 return gfx::Screen::GetNativeScreen()->GetDisplayNearestPoint(
37 rect.CenterPoint()).bounds();
40 DISALLOW_COPY_AND_ASSIGN(ModeIndicatorFrameView);
43 } // namespace
46 ModeIndicatorView::ModeIndicatorView(gfx::NativeView parent,
47 const gfx::Rect& cursor_bounds,
48 const base::string16& label)
49 : cursor_bounds_(cursor_bounds),
50 label_view_(new views::Label(label)) {
51 set_can_activate(false);
52 set_accept_events(false);
53 set_parent_window(parent);
54 set_shadow(views::BubbleBorder::NO_SHADOW);
55 set_arrow(views::BubbleBorder::TOP_CENTER);
58 ModeIndicatorView::~ModeIndicatorView() {}
60 void ModeIndicatorView::ShowAndFadeOut() {
61 wm::SetWindowVisibilityAnimationTransition(
62 GetWidget()->GetNativeView(),
63 wm::ANIMATE_HIDE);
64 GetWidget()->Show();
65 timer_.Start(FROM_HERE,
66 base::TimeDelta::FromMilliseconds(kShowingDuration),
67 GetWidget(),
68 &views::Widget::Close);
71 gfx::Size ModeIndicatorView::GetPreferredSize() const {
72 gfx::Size size = label_view_->GetPreferredSize();
73 size.SetToMax(gfx::Size(kMinSize, kMinSize));
74 return size;
77 const char* ModeIndicatorView::GetClassName() const {
78 return "ModeIndicatorView";
81 void ModeIndicatorView::Init() {
82 SetLayoutManager(new views::FillLayout());
83 AddChildView(label_view_);
85 SetAnchorRect(cursor_bounds_);
88 views::NonClientFrameView* ModeIndicatorView::CreateNonClientFrameView(
89 views::Widget* widget) {
90 views::BubbleFrameView* frame = new ModeIndicatorFrameView(margins());
91 // arrow adjustment in BubbleDelegateView is unnecessary because arrow
92 // of this bubble is always center.
93 frame->SetBubbleBorder(scoped_ptr<views::BubbleBorder>(
94 new views::BubbleBorder(arrow(), shadow(), color())));
95 return frame;
98 } // namespace ime
99 } // namespace ui