OLD | NEW |
| (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 #include "chrome/browser/chromeos/input_method/mode_indicator_widget.h" | |
5 | |
6 #include "ash/shell.h" | |
7 #include "ash/shell_window_ids.h" | |
8 #include "ash/wm/window_animations.h" | |
9 #include "chrome/browser/chromeos/input_method/mode_indicator_view.h" | |
10 #include "ui/gfx/color_utils.h" | |
11 #include "ui/native_theme/native_theme.h" | |
12 #include "ui/views/bubble/bubble_border.h" | |
13 | |
14 namespace chromeos { | |
15 namespace input_method { | |
16 | |
17 ModeIndicatorWidget::ModeIndicatorWidget() | |
18 : mode_view_(new input_method::ModeIndicatorView) { | |
19 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | |
20 | |
21 // This class is owned by controller impl as well as other components like | |
22 // info_list. | |
23 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
24 | |
25 // Show the window always on top | |
26 params.parent = ash::Shell::GetContainer( | |
27 ash::Shell::GetTargetRootWindow(), | |
28 ash::internal::kShellWindowId_InputMethodContainer); | |
29 | |
30 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | |
31 Init(params); | |
32 views::corewm::SetWindowVisibilityAnimationType( | |
33 GetNativeView(), | |
34 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
35 | |
36 // Pass the ownership. | |
37 SetContentsView(mode_view_); | |
38 } | |
39 | |
40 ModeIndicatorWidget::~ModeIndicatorWidget() { | |
41 } | |
42 | |
43 void ModeIndicatorWidget::SetCursorBounds(const gfx::Rect& cursor_bounds) { | |
44 cursor_bounds_ = cursor_bounds; | |
45 gfx::Rect bound(GetClientAreaBoundsInScreen()); | |
46 bound.set_x(cursor_bounds.x() - bound.width() / 2); | |
47 bound.set_y(cursor_bounds.bottom()); | |
48 SetBounds(bound); | |
49 } | |
50 | |
51 void ModeIndicatorWidget::SetLabelTextUtf8(const std::string& text_utf8) { | |
52 DCHECK(mode_view_); | |
53 | |
54 mode_view_->SetLabelTextUtf8(text_utf8); | |
55 SetSize(mode_view_->size()); | |
56 SetCursorBounds(cursor_bounds_); | |
57 } | |
58 | |
59 } // namespace input_method | |
60 } // namespace chromeos | |
OLD | NEW |