| 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/status_area/status_area_view.h" | 5 #include "ash/status_area/status_area_view.h" |
| 6 | 6 |
| 7 #include "ash/ash_export.h" | 7 #include "ash/ash_export.h" |
| 8 #include "ash/focus_cycler.h" |
| 8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "grit/ui_resources.h" | 12 #include "grit/ui_resources.h" |
| 12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 | 18 |
| 18 namespace ash { | 19 namespace ash { |
| 19 namespace internal { | 20 namespace internal { |
| 20 | 21 |
| 21 StatusAreaView::StatusAreaView() | 22 StatusAreaView::StatusAreaView() |
| 22 : status_mock_(*ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 23 : status_mock_(*ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 23 IDR_AURA_STATUS_MOCK).ToSkBitmap()) { | 24 IDR_AURA_STATUS_MOCK).ToSkBitmap()), |
| 25 focus_cycler_for_testing_(NULL) { |
| 24 } | 26 } |
| 25 StatusAreaView::~StatusAreaView() { | 27 StatusAreaView::~StatusAreaView() { |
| 26 } | 28 } |
| 27 | 29 |
| 30 void StatusAreaView::SetFocusCyclerForTesting(const FocusCycler* focus_cycler) { |
| 31 focus_cycler_for_testing_ = focus_cycler; |
| 32 } |
| 33 |
| 28 gfx::Size StatusAreaView::GetPreferredSize() { | 34 gfx::Size StatusAreaView::GetPreferredSize() { |
| 29 return gfx::Size(status_mock_.width(), status_mock_.height()); | 35 return gfx::Size(status_mock_.width(), status_mock_.height()); |
| 30 } | 36 } |
| 31 | 37 |
| 32 views::Widget* StatusAreaView::GetWidget() { | 38 views::Widget* StatusAreaView::GetWidget() { |
| 33 return View::GetWidget(); | 39 return View::GetWidget(); |
| 34 } | 40 } |
| 35 | 41 |
| 36 const views::Widget* StatusAreaView::GetWidget() const { | 42 const views::Widget* StatusAreaView::GetWidget() const { |
| 37 return View::GetWidget(); | 43 return View::GetWidget(); |
| 38 } | 44 } |
| 39 | 45 |
| 46 bool StatusAreaView::CanActivate() const { |
| 47 // We don't want mouse clicks to activate us, but we need to allow |
| 48 // activation when the user is using the keyboard (FocusCycler). |
| 49 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ? |
| 50 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler(); |
| 51 return focus_cycler->widget_activating() == GetWidget(); |
| 52 } |
| 53 |
| 40 void StatusAreaView::OnPaint(gfx::Canvas* canvas) { | 54 void StatusAreaView::OnPaint(gfx::Canvas* canvas) { |
| 41 canvas->DrawBitmapInt(status_mock_, 0, 0); | 55 canvas->DrawBitmapInt(status_mock_, 0, 0); |
| 42 } | 56 } |
| 43 | 57 |
| 44 ASH_EXPORT views::Widget* CreateStatusArea(views::View* contents) { | 58 ASH_EXPORT views::Widget* CreateStatusArea(views::View* contents) { |
| 45 StatusAreaView* status_area_view = new StatusAreaView; | 59 StatusAreaView* status_area_view = new StatusAreaView; |
| 46 if (!contents) | 60 if (!contents) |
| 47 contents = status_area_view; | 61 contents = status_area_view; |
| 48 views::Widget* widget = new views::Widget; | 62 views::Widget* widget = new views::Widget; |
| 49 views::Widget::InitParams params( | 63 views::Widget::InitParams params( |
| 50 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 64 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 51 gfx::Size ps = contents->GetPreferredSize(); | 65 gfx::Size ps = contents->GetPreferredSize(); |
| 52 params.bounds = gfx::Rect(0, 0, ps.width(), ps.height()); | 66 params.bounds = gfx::Rect(0, 0, ps.width(), ps.height()); |
| 53 params.delegate = status_area_view; | 67 params.delegate = status_area_view; |
| 54 params.parent = Shell::GetInstance()->GetContainer( | 68 params.parent = Shell::GetInstance()->GetContainer( |
| 55 ash::internal::kShellWindowId_StatusContainer); | 69 ash::internal::kShellWindowId_StatusContainer); |
| 56 params.transparent = true; | 70 params.transparent = true; |
| 57 widget->Init(params); | 71 widget->Init(params); |
| 58 widget->set_focus_on_creation(false); | 72 widget->set_focus_on_creation(false); |
| 59 widget->SetContentsView(contents); | 73 widget->SetContentsView(contents); |
| 60 widget->Show(); | 74 widget->Show(); |
| 61 widget->GetNativeView()->SetName("StatusAreaView"); | 75 widget->GetNativeView()->SetName("StatusAreaView"); |
| 62 return widget; | 76 return widget; |
| 63 } | 77 } |
| 64 | 78 |
| 65 } // namespace internal | 79 } // namespace internal |
| 66 } // namespace ash | 80 } // namespace ash |
| OLD | NEW |