| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "athena/screen/background_controller.h" | |
| 6 | |
| 7 #include "base/strings/stringprintf.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "extensions/shell/common/version.h" | |
| 10 #include "third_party/skia/include/core/SkColor.h" | |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/compositor/layer.h" | |
| 13 #include "ui/gfx/canvas.h" | |
| 14 #include "ui/gfx/image/image_skia.h" | |
| 15 #include "ui/views/controls/label.h" | |
| 16 #include "ui/views/view.h" | |
| 17 #include "ui/views/widget/widget.h" | |
| 18 | |
| 19 namespace athena { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const SkColor kVersionColor = SK_ColorWHITE; | |
| 24 const SkColor kVersionBackground = SK_ColorTRANSPARENT; | |
| 25 const SkColor kVersionShadow = 0xB0000000; | |
| 26 const int kVersionShadowBlur = 10; | |
| 27 | |
| 28 class VersionView : public views::Label { | |
| 29 public: | |
| 30 VersionView() { | |
| 31 SetEnabledColor(kVersionColor); | |
| 32 SetBackgroundColor(kVersionBackground); | |
| 33 SetShadows(gfx::ShadowValues(1, gfx::ShadowValue(gfx::Point(0, 1), | |
| 34 kVersionShadowBlur, | |
| 35 kVersionShadow))); | |
| 36 SetText(base::UTF8ToUTF16(base::StringPrintf("%s (Build %s)", | |
| 37 PRODUCT_VERSION, | |
| 38 LAST_CHANGE))); | |
| 39 SetBoundsRect(gfx::Rect(gfx::Point(), GetPreferredSize())); | |
| 40 } | |
| 41 virtual ~VersionView() { | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(VersionView); | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 class BackgroundView : public views::View { | |
| 51 public: | |
| 52 BackgroundView() { | |
| 53 AddChildView(new VersionView); | |
| 54 } | |
| 55 virtual ~BackgroundView() {} | |
| 56 | |
| 57 void SetImage(const gfx::ImageSkia& image) { | |
| 58 image_ = image; | |
| 59 SchedulePaint(); | |
| 60 } | |
| 61 | |
| 62 // views::View | |
| 63 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 64 canvas->DrawImageInt(image_, | |
| 65 0, | |
| 66 0, | |
| 67 image_.width(), | |
| 68 image_.height(), | |
| 69 0, | |
| 70 0, | |
| 71 width(), | |
| 72 height(), | |
| 73 true); | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 gfx::ImageSkia image_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(BackgroundView); | |
| 80 }; | |
| 81 | |
| 82 BackgroundController::BackgroundController(aura::Window* container) { | |
| 83 // TODO(oshima): Using widget to just draw an image is probably | |
| 84 // overkill. Just use WindowDelegate to draw the background and | |
| 85 // remove dependency to ui/views. | |
| 86 | |
| 87 views::Widget* background_widget = new views::Widget; | |
| 88 views::Widget::InitParams params( | |
| 89 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 90 params.accept_events = false; | |
| 91 params.parent = container; | |
| 92 background_widget->Init(params); | |
| 93 background_widget->GetNativeWindow()->layer()->SetMasksToBounds(true); | |
| 94 background_view_ = new BackgroundView; | |
| 95 background_widget->SetContentsView(background_view_); | |
| 96 background_widget->GetNativeView()->SetName("BackgroundWidget"); | |
| 97 background_widget->Show(); | |
| 98 } | |
| 99 | |
| 100 BackgroundController::~BackgroundController() { | |
| 101 // background_widget is owned by the container and will be deleted | |
| 102 // when the container is deleted. | |
| 103 } | |
| 104 | |
| 105 void BackgroundController::SetImage(const gfx::ImageSkia& image) { | |
| 106 // TODO(oshima): implement cross fede animation. | |
| 107 background_view_->SetImage(image); | |
| 108 } | |
| 109 | |
| 110 } // namespace athena | |
| OLD | NEW |