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; | |
| 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 // Class overriding views::Label::GetPreferredSize(). | |
| 30 class ModeIndicatorLabel : public views::Label { | |
| 31 public: | |
| 32 explicit ModeIndicatorLabel(const string16& label) | |
| 33 : views::Label(label) {} | |
| 34 | |
| 35 virtual ~ModeIndicatorLabel() {} | |
| 36 | |
| 37 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
|
Jun Mukai
2013/12/02 21:08:41
You don't have to inherit Label. Actually you can
Hiro Komatsu
2013/12/03 02:39:36
Done.
| |
| 38 gfx::Size size = views::Label::GetPreferredSize(); | |
| 39 size.SetToMax(gfx::Size(kMinSize, kMinSize)); | |
| 40 return size; | |
| 41 } | |
| 42 }; | |
| 43 | |
| 44 | |
| 45 ModeIndicatorDelegateView::ModeIndicatorDelegateView( | |
| 46 const gfx::Rect& cursor_bounds, | |
| 47 const string16& label) | |
| 48 : cursor_bounds_(cursor_bounds), | |
| 49 label_(label) { | |
| 50 set_use_focusless(true); | |
| 51 set_accept_events(false); | |
| 52 set_shadow(views::BubbleBorder::NO_SHADOW); | |
|
Jun Mukai
2013/12/02 21:08:41
should specify parent_window?
Otherwise it will be
Hiro Komatsu
2013/12/03 02:39:36
Done.
| |
| 53 | |
| 54 const gfx::Rect screen_bounds = | |
| 55 ash::Shell::GetScreen()->GetDisplayMatching(cursor_bounds).work_area(); | |
| 56 if (screen_bounds.bottom() - cursor_bounds.bottom() > kSizeMargin) | |
| 57 set_arrow(views::BubbleBorder::TOP_CENTER); | |
| 58 else | |
| 59 set_arrow(views::BubbleBorder::BOTTOM_CENTER); | |
|
Jun Mukai
2013/12/02 21:08:41
you don't have to do that. Bubble can take care of
Hiro Komatsu
2013/12/03 02:39:36
It seems a bug of BubbleFrameView. Till the bug i
| |
| 60 } | |
| 61 | |
| 62 ModeIndicatorDelegateView::~ModeIndicatorDelegateView() {} | |
| 63 | |
| 64 void ModeIndicatorDelegateView::FadeOut() { | |
| 65 StartFade(false); | |
| 66 } | |
| 67 | |
| 68 void ModeIndicatorDelegateView::ShowAndFadeOut() { | |
| 69 views::corewm::SetWindowVisibilityAnimationTransition( | |
| 70 GetWidget()->GetNativeView(), | |
| 71 views::corewm::ANIMATE_HIDE); | |
| 72 GetWidget()->Show(); | |
| 73 timer_.Start(FROM_HERE, | |
| 74 base::TimeDelta::FromMilliseconds(kShowingDuration), | |
| 75 this, | |
| 76 &ModeIndicatorDelegateView::FadeOut); | |
| 77 } | |
| 78 | |
| 79 void ModeIndicatorDelegateView::Init() { | |
| 80 SetLayoutManager(new views::FillLayout()); | |
| 81 ModeIndicatorLabel* label_view = new ModeIndicatorLabel(label_); | |
| 82 AddChildView(label_view); | |
| 83 | |
| 84 SetAnchorRect(cursor_bounds_); | |
| 85 } | |
| 86 | |
| 87 } // namespace input_method | |
| 88 } // namespace chromeos | |
| OLD | NEW |