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

Side by Side Diff: chrome/browser/ui/views/aura/app_list_window.cc

Issue 8394003: [Aura] A temp app list window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync and address comments in #1 Created 9 years, 1 month 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) 2011 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/ui/views/aura/app_list_window.h"
6
7 #include "base/bind.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/views/dom_view.h"
10 #include "content/browser/renderer_host/render_view_host.h"
11 #include "content/browser/renderer_host/render_widget_host_view.h"
12 #include "views/widget/widget.h"
13 #include "ui/aura/desktop.h"
14 #include "ui/gfx/screen.h"
15
16 namespace {
17
18 // Gets preferred bounds of app list window in show/hide state.
19 gfx::Rect GetPreferredBounds(bool show) {
20 // The y-axis offset used at the beginning of showing animation.
21 static const int kMoveUpAnimationOffset = 50;
22
23 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint();
24 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint(cursor);
25 gfx::Rect widget_bounds(work_area);
26 widget_bounds.Inset(150, 100);
27 if (!show)
28 widget_bounds.Offset(0, kMoveUpAnimationOffset);
29
30 return widget_bounds;
31 }
32
33 } // namespace
34
35 // static
36 AppListWindow* AppListWindow::instance_ = NULL;
37
38 // static
39 void AppListWindow::Show(bool show) {
40 if (!instance_) {
41 // TODO(xiyuan): Fix first time animation jankiness.
42 instance_ = new AppListWindow;
43 instance_->Init();
44 }
45
46 instance_->Show(show, true);
47 }
48
49 bool AppListWindow::IsShowing() {
50 return instance_ && instance_->is_showing();
51 }
52
53 AppListWindow::AppListWindow()
54 : widget_(NULL),
55 contents_(NULL),
56 is_showing_(false) {
57 }
58
59 AppListWindow::~AppListWindow() {
60 }
61
62 void AppListWindow::DeleteDelegate() {
63 delete this;
64 }
65
66 views::View* AppListWindow::GetContentsView() {
67 return contents_;
68 }
69
70 void AppListWindow::WindowClosing() {
71 aura::Desktop::GetInstance()->RemoveObserver(this);
72 widget_ = NULL;
73 }
74
75 views::Widget* AppListWindow::GetWidget() {
76 return widget_;
77 }
78
79 const views::Widget* AppListWindow::GetWidget() const {
80 return widget_;
81 }
82
83 void AppListWindow::OnActiveWindowChanged(aura::Window* active) {
84 if (widget_ && !widget_->IsActive() && is_showing_)
85 Show(false, true);
86 }
87
88 void AppListWindow::Init() {
89 DCHECK(!widget_ && !contents_);
90
91 contents_ = new DOMView();
92 contents_->Init(ProfileManager::GetDefaultProfile(), NULL);
93 contents_->LoadURL(GURL("chrome://newtab#applist"));
94
95 // Use a background with transparency to trigger transparent webkit.
96 SkBitmap background;
97 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
98 background.allocPixels();
99 background.eraseARGB(0x00, 0x00, 0x00, 0x00);
100
101 TabContents* tab = contents_->dom_contents()->tab_contents();
102 RenderViewHost* host = tab->render_view_host();
103 host->view()->SetBackground(background);
104
105 views::Widget::InitParams widget_params(
106 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
107 widget_params.bounds = GetPreferredBounds(false);
108 widget_params.delegate = this;
109
110 widget_ = new views::Widget;
111 widget_->Init(widget_params);
112 widget_->SetContentsView(contents_);
113 widget_->SetOpacity(0);
114
115 aura::Desktop::GetInstance()->AddObserver(this);
116 }
117
118 void AppListWindow::Show(bool show, bool animate) {
119 if (show == is_showing_)
120 return;
121
122 is_showing_ = show;
123
124 if (animate) {
125 gfx::Point dummy;
126 ui::Layer* layer;
127 widget_->CalculateOffsetToAncestorWithLayer(&dummy, &layer);
128
129 layer->SetAnimation(aura::Window::CreateDefaultAnimation());
130 layer->SetBounds(GetPreferredBounds(show));
131 layer->SetOpacity(show ? 1.0 : 0.0);
132 }
133
134 if (show) {
135 widget_->Activate();
136 widget_->Show();
137 } else {
138 instance_ = NULL; // Closing and don't reuse this instance_.
139
140 if (animate) {
141 // TODO(xiyuan): Properly close widget after animation finishes.
142 MessageLoop::current()->PostDelayedTask(
143 FROM_HERE,
144 base::Bind(&views::Widget::Close, base::Unretained(widget_)),
145 1000);
146 } else {
147 widget_->Close();
148 }
149 }
150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698