Chromium Code Reviews| 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 | |
| 5 #include "chrome/browser/chromeos/input_method/mode_indicator_delegate_view.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/wm/window_animations.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "ui/views/bubble/bubble_delegate.h" | |
| 11 #include "ui/views/controls/label.h" | |
| 12 #include "ui/views/layout/fill_layout.h" | |
| 13 | |
| 14 namespace chromeos { | |
| 15 namespace input_method { | |
| 16 | |
| 17 namespace { | |
| 18 // Minimum size of inner contents in pixel. | |
| 19 const int kMinSize = 43; | |
|
Jun Mukai
2013/12/03 01:09:28
Noticed that the bubble is slightly bigger than th
| |
| 20 | |
| 21 // If the cursor bounds is lower than this margin in pixel, the mode | |
| 22 // indicator is shown above the cursor instead on bottom. | |
| 23 const int kSizeMargin = 75; | |
| 24 | |
| 25 // After this duration in msec, the mode inicator will be fading out. | |
| 26 const int kShowingDuration = 500; | |
| 27 } // namespace | |
| 28 | |
| 29 | |
| 30 ModeIndicatorDelegateView::ModeIndicatorDelegateView( | |
| 31 const gfx::Rect& cursor_bounds, | |
| 32 const string16& label) | |
| 33 : cursor_bounds_(cursor_bounds), | |
| 34 label_view_(new views::Label(label)) { | |
| 35 set_use_focusless(true); | |
| 36 set_accept_events(false); | |
| 37 set_shadow(views::BubbleBorder::NO_SHADOW); | |
| 38 | |
| 39 const gfx::Rect screen_bounds = | |
| 40 ash::Shell::GetScreen()->GetDisplayMatching(cursor_bounds).work_area(); | |
| 41 if (screen_bounds.bottom() - cursor_bounds.bottom() > kSizeMargin) | |
| 42 set_arrow(views::BubbleBorder::TOP_CENTER); | |
| 43 else | |
| 44 set_arrow(views::BubbleBorder::BOTTOM_CENTER); | |
| 45 } | |
| 46 | |
| 47 ModeIndicatorDelegateView::~ModeIndicatorDelegateView() {} | |
| 48 | |
| 49 void ModeIndicatorDelegateView::FadeOut() { | |
| 50 StartFade(false); | |
| 51 } | |
| 52 | |
| 53 void ModeIndicatorDelegateView::ShowAndFadeOut() { | |
| 54 views::corewm::SetWindowVisibilityAnimationTransition( | |
| 55 GetWidget()->GetNativeView(), | |
| 56 views::corewm::ANIMATE_HIDE); | |
| 57 GetWidget()->Show(); | |
| 58 timer_.Start(FROM_HERE, | |
| 59 base::TimeDelta::FromMilliseconds(kShowingDuration), | |
| 60 this, | |
| 61 &ModeIndicatorDelegateView::FadeOut); | |
| 62 } | |
| 63 | |
| 64 gfx::Size ModeIndicatorDelegateView::GetPreferredSize() { | |
| 65 gfx::Size size = label_view_->GetPreferredSize(); | |
| 66 size.SetToMax(gfx::Size(kMinSize, kMinSize)); | |
| 67 return size; | |
| 68 } | |
| 69 | |
| 70 void ModeIndicatorDelegateView::Init() { | |
| 71 SetLayoutManager(new views::FillLayout()); | |
| 72 AddChildView(label_view_); | |
| 73 | |
| 74 SetAnchorRect(cursor_bounds_); | |
| 75 } | |
| 76 | |
| 77 } // namespace input_method | |
| 78 } // namespace chromeos | |
| OLD | NEW |