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"
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/gfx/rect.h"
12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/bubble/bubble_border.h"
16 namespace input_method {
18 ModeIndicatorWidget::ModeIndicatorWidget()
19 : mode_view_(new input_method::ModeIndicatorView) {
20 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
22 // This class is owned by controller impl as well as other components like
24 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
26 // Show the window always on top
27 params.parent = ash::Shell::GetContainer(
28 ash::Shell::GetTargetRootWindow(),
29 ash::internal::kShellWindowId_InputMethodContainer);
31 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
33 views::corewm::SetWindowVisibilityAnimationType(
35 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
37 // Pass the ownership.
38 SetContentsView(mode_view_);
40 SetBounds(gfx::Rect(0, 0, 60, 60)); // x, y, w, h
43 ModeIndicatorWidget::~ModeIndicatorWidget() {
46 void ModeIndicatorWidget::SetCursorLocation(const gfx::Rect& cursor_location) {
47 gfx::Rect bound(GetClientAreaBoundsInScreen());
48 bound.set_x(cursor_location.x() - bound.width() / 2);
49 bound.set_y(cursor_location.bottom());
53 void ModeIndicatorWidget::SetLabelTextUtf8(const std::string& text_utf8) {
55 // TODO(komatsu): Nice to resize the widget size based on the text length.
56 mode_view_->SetLabelTextUtf8(text_utf8);
60 } // namespace input_method
61 } // namespace chromeos