Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: ash/status_area/status_area_view.cc

Issue 10140017: ash: Some code-cleanup in the system-tray code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/status_area/status_area_view.h"
6
7 #include "ash/ash_export.h"
8 #include "ash/focus_cycler.h"
9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h"
11 #include "base/utf_string_conversions.h"
12 #include "grit/ui_resources.h"
13 #include "ui/aura/root_window.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/image/image.h"
17 #include "ui/views/accessible_pane_view.h"
18 #include "ui/views/layout/fill_layout.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace ash {
22 namespace internal {
23
24 StatusAreaView::StatusAreaView()
25 : focus_cycler_for_testing_(NULL) {
26 SetLayoutManager(new views::FillLayout);
27 }
28
29 StatusAreaView::~StatusAreaView() {
30 }
31
32 void StatusAreaView::SetFocusCyclerForTesting(const FocusCycler* focus_cycler) {
33 focus_cycler_for_testing_ = focus_cycler;
34 }
35
36 views::View* StatusAreaView::GetDefaultFocusableChild() {
37 return child_at(0);
38 }
39
40 bool StatusAreaView::AcceleratorPressed(const ui::Accelerator& accelerator) {
41 if (accelerator.key_code() == ui::VKEY_ESCAPE) {
42 RemovePaneFocus();
43 GetFocusManager()->ClearFocus();
44 return true;
45 }
46 return false;
47 }
48
49 views::Widget* StatusAreaView::GetWidget() {
50 return View::GetWidget();
51 }
52
53 const views::Widget* StatusAreaView::GetWidget() const {
54 return View::GetWidget();
55 }
56
57 bool StatusAreaView::CanActivate() const {
58 // We don't want mouse clicks to activate us, but we need to allow
59 // activation when the user is using the keyboard (FocusCycler).
60 const FocusCycler* focus_cycler = focus_cycler_for_testing_ ?
61 focus_cycler_for_testing_ : Shell::GetInstance()->focus_cycler();
62 return focus_cycler->widget_activating() == GetWidget();
63 }
64
65 void StatusAreaView::DeleteDelegate() {
66 }
67
68 ASH_EXPORT views::Widget* CreateStatusArea(views::View* contents) {
69 if (!contents) {
70 contents = new views::View;
71 contents->set_focusable(true);
72 }
73 StatusAreaView* status_area_view = new StatusAreaView;
74 views::Widget* widget = new views::Widget;
75 views::Widget::InitParams params(
76 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
77 gfx::Size ps = contents->GetPreferredSize();
78 params.bounds = gfx::Rect(0, 0, ps.width(), ps.height());
79 params.delegate = status_area_view;
80 params.parent = Shell::GetInstance()->GetContainer(
81 ash::internal::kShellWindowId_StatusContainer);
82 params.transparent = true;
83 widget->Init(params);
84 widget->set_focus_on_creation(false);
85 status_area_view->AddChildView(contents);
86 widget->SetContentsView(status_area_view);
87 widget->Show();
88 widget->GetNativeView()->SetName("StatusAreaView");
89 return widget;
90 }
91
92 } // namespace internal
93 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698