| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/monitor/secondary_monitor_view.h" | 5 #include "ash/monitor/secondary_monitor_view.h" |
| 6 | 6 |
| 7 #include "grit/ash_strings.h" |
| 7 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/base/l10n/l10n_util.h" |
| 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/views/background.h" |
| 13 #include "ui/views/controls/label.h" |
| 9 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 10 #include "ui/views/background.h" | 15 #include "ui/views/widget/widget.h" |
| 11 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
| 12 #include "ui/views/widget/widget.h" | |
| 13 | 17 |
| 14 namespace ash { | 18 namespace ash { |
| 15 namespace { | 19 namespace { |
| 16 | 20 |
| 17 const SkColor kBackground = SkColorSetRGB(0x33, 0x33, 0x33); | 21 // Colors for the background, the message text and the shortcut text. |
| 22 const SkColor kBackgroundColor = SkColorSetRGB(0x33, 0x33, 0x33); |
| 23 const SkColor kMessageColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
| 24 const SkColor kShortcutColor = SkColorSetRGB(0x8f, 0x8f, 0x8f); |
| 18 | 25 |
| 19 // A view to be displayed on secondary monitor. | 26 // A view to be displayed on secondary monitor. |
| 20 class SecondaryMonitorView : public views::WidgetDelegateView { | 27 class SecondaryMonitorView : public views::WidgetDelegateView { |
| 21 public: | 28 public: |
| 22 SecondaryMonitorView() { | 29 SecondaryMonitorView() { |
| 23 set_background(views::Background::CreateSolidBackground(kBackground)); | 30 Init(); |
| 24 } | 31 } |
| 25 ~SecondaryMonitorView() { | 32 virtual ~SecondaryMonitorView() { |
| 26 } | 33 } |
| 34 |
| 35 void Init() { |
| 36 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 37 |
| 38 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 39 message_ = new views::Label( |
| 40 l10n_util::GetStringUTF16(IDS_ASH_SECONDARY_MONITOR)); |
| 41 message_->SetAutoColorReadabilityEnabled(false); |
| 42 message_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 43 message_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 44 message_->SetEnabledColor(kMessageColor); |
| 45 AddChildView(message_); |
| 46 |
| 47 // TODO(oshima): Add image for fullscreen shortcut. |
| 48 shortcut_ = new views::Label( |
| 49 l10n_util::GetStringUTF16(IDS_ASH_SECONDARY_MONITOR_SHORTCUT)); |
| 50 shortcut_->SetAutoColorReadabilityEnabled(false); |
| 51 shortcut_->SetFont(rb.GetFont(ui::ResourceBundle::SmallFont)); |
| 52 shortcut_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 53 shortcut_->SetEnabledColor(kShortcutColor); |
| 54 AddChildView(shortcut_); |
| 55 } |
| 56 |
| 57 virtual void Layout() { |
| 58 const int kMessageMargin = 20; |
| 59 const float kShortcutPositionFromBottom = 50; |
| 60 gfx::Rect b = bounds(); |
| 61 int bottom = bounds().height() - kShortcutPositionFromBottom; |
| 62 int shortcut_height = shortcut_->GetHeightForWidth(b.width()); |
| 63 shortcut_->SetBounds(0, bottom, b.width(), shortcut_height); |
| 64 |
| 65 int msg_height = message_->GetHeightForWidth(b.width()); |
| 66 bottom -= msg_height + kMessageMargin; |
| 67 message_->SetBounds(0, bottom, bounds().width(), msg_height); |
| 68 } |
| 69 |
| 70 private: |
| 71 views::Label* message_; |
| 72 views::Label* shortcut_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SecondaryMonitorView); |
| 27 }; | 75 }; |
| 28 | 76 |
| 29 } // namespace | 77 } // namespace |
| 30 | 78 |
| 31 views::Widget* CreateSecondaryMonitorWidget(aura::Window* parent) { | 79 views::Widget* CreateSecondaryMonitorWidget(aura::Window* parent) { |
| 32 views::Widget* desktop_widget = new views::Widget; | 80 views::Widget* desktop_widget = new views::Widget; |
| 33 views::Widget::InitParams params( | 81 views::Widget::InitParams params( |
| 34 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 82 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 35 SecondaryMonitorView* view = new SecondaryMonitorView(); | 83 SecondaryMonitorView* view = new SecondaryMonitorView(); |
| 36 params.delegate = view; | 84 params.delegate = view; |
| 37 params.parent = parent; | 85 params.parent = parent; |
| 38 desktop_widget->Init(params); | 86 desktop_widget->Init(params); |
| 39 desktop_widget->SetContentsView(view); | 87 desktop_widget->SetContentsView(view); |
| 40 desktop_widget->Show(); | 88 desktop_widget->Show(); |
| 41 desktop_widget->GetNativeView()->SetName("SecondaryMonitor"); | 89 desktop_widget->GetNativeView()->SetName("SecondaryMonitor"); |
| 42 return desktop_widget; | 90 return desktop_widget; |
| 43 } | 91 } |
| 44 | 92 |
| 45 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |