forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathime_mode_indicator_view.cc
111 lines (90 loc) · 3.5 KB
/
ime_mode_indicator_view.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2018 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 "ash/ime/ime_mode_indicator_view.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/window_util.h"
#include "base/logging.h"
#include "base/macros.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/wm/core/window_animations.h"
namespace ash {
namespace {
// Minimum size of inner contents in pixel.
// 43 is the designed size including the default margin (6 * 2).
const int kMinSize = 31;
// After this duration in msec, the mode inicator will be fading out.
const int kShowingDuration = 500;
class ModeIndicatorFrameView : public views::BubbleFrameView {
public:
explicit ModeIndicatorFrameView()
: views::BubbleFrameView(gfx::Insets(), gfx::Insets()) {}
~ModeIndicatorFrameView() override {}
private:
// views::BubbleFrameView overrides:
gfx::Rect GetAvailableScreenBounds(const gfx::Rect& rect) const override {
return display::Screen::GetScreen()
->GetDisplayNearestPoint(rect.CenterPoint())
.bounds();
}
DISALLOW_COPY_AND_ASSIGN(ModeIndicatorFrameView);
};
} // namespace
ImeModeIndicatorView::ImeModeIndicatorView(const gfx::Rect& cursor_bounds,
const base::string16& label)
: cursor_bounds_(cursor_bounds), label_view_(new views::Label(label)) {
SetCanActivate(false);
set_accept_events(false);
set_shadow(views::BubbleBorder::BIG_SHADOW);
SetArrow(views::BubbleBorder::TOP_CENTER);
}
ImeModeIndicatorView::~ImeModeIndicatorView() = default;
void ImeModeIndicatorView::ShowAndFadeOut() {
::wm::SetWindowVisibilityAnimationTransition(GetWidget()->GetNativeView(),
::wm::ANIMATE_HIDE);
GetWidget()->Show();
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kShowingDuration),
GetWidget(), &views::Widget::Close);
}
void ImeModeIndicatorView::OnBeforeBubbleWidgetInit(
views::Widget::InitParams* params,
views::Widget* widget) const {
aura::Window* window = wm::GetActiveWindow();
if (window) { // Null check for tests.
params->parent = Shell::GetContainer(window->GetRootWindow(),
kShellWindowId_SettingBubbleContainer);
} else {
params->parent = Shell::GetPrimaryRootWindow();
}
}
gfx::Size ImeModeIndicatorView::CalculatePreferredSize() const {
gfx::Size size = label_view_->GetPreferredSize();
size.SetToMax(gfx::Size(kMinSize, kMinSize));
return size;
}
const char* ImeModeIndicatorView::GetClassName() const {
return "ImeModeIndicatorView";
}
int ImeModeIndicatorView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_NONE;
}
void ImeModeIndicatorView::Init() {
SetLayoutManager(std::make_unique<views::FillLayout>());
AddChildView(label_view_);
SetAnchorRect(cursor_bounds_);
}
views::NonClientFrameView* ImeModeIndicatorView::CreateNonClientFrameView(
views::Widget* widget) {
views::BubbleFrameView* frame = new ModeIndicatorFrameView();
// arrow adjustment in BubbleDialogDelegateView is unnecessary because arrow
// of this bubble is always center.
frame->SetBubbleBorder(std::unique_ptr<views::BubbleBorder>(
new views::BubbleBorder(arrow(), GetShadow(), color())));
return frame;
}
} // namespace ash