- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / input_method / mode_indicator_widget.cc
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/gfx/rect.h"
12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/bubble/bubble_border.h"
14
15 namespace chromeos {
16 namespace input_method {
17
18 ModeIndicatorWidget::ModeIndicatorWidget()
19     : mode_view_(new input_method::ModeIndicatorView) {
20   views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
21
22   // This class is owned by controller impl as well as other components like
23   // info_list.
24   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
25
26   // Show the window always on top
27   params.parent = ash::Shell::GetContainer(
28       ash::Shell::GetTargetRootWindow(),
29       ash::internal::kShellWindowId_InputMethodContainer);
30
31   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
32   Init(params);
33   views::corewm::SetWindowVisibilityAnimationType(
34       GetNativeView(),
35       views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
36
37   // Pass the ownership.
38   SetContentsView(mode_view_);
39
40   SetBounds(gfx::Rect(0, 0, 60, 60));  // x, y, w, h
41 }
42
43 ModeIndicatorWidget::~ModeIndicatorWidget() {
44 }
45
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());
50   SetBounds(bound);
51 }
52
53 void ModeIndicatorWidget::SetLabelTextUtf8(const std::string& text_utf8) {
54   if (mode_view_) {
55     // TODO(komatsu): Nice to resize the widget size based on the text length.
56     mode_view_->SetLabelTextUtf8(text_utf8);
57   }
58 }
59
60 }  // namespace input_method
61 }  // namespace chromeos