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

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: Created 9 years, 2 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) 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 "chrome/browser/profiles/profile_manager.h"
8 #include "chrome/browser/ui/views/dom_view.h"
9 #include "content/browser/renderer_host/render_view_host.h"
10 #include "content/browser/renderer_host/render_widget_host_view.h"
11 #include "views/widget/widget.h"
12 #include "ui/aura/desktop.h"
13 #include "ui/base/animation/slide_animation.h"
14
15 namespace {
16
17 // The duration of the animation in milliseconds.
18 const int kAnimationDurationMS = 200;
19
20 // The y-axis offset used at the beginning of showing animation.
21 const int kMoveUpAnimationOffset = 50;
22
23 // Gets preferred position and size of app list window.
24 gfx::Rect GetPreferredPosition() {
25 aura::Desktop* desktop_window = aura::Desktop::GetInstance();
sky 2011/10/25 17:59:27 Go through screen instead of this. That way you ca
xiyuan 2011/10/27 22:51:29 Done.
26 gfx::Rect widget_bounds(desktop_window->bounds());
27 widget_bounds.Inset(150, 100);
28
29 return widget_bounds;
30 }
31
32 }
sky 2011/10/25 17:59:27 nit: // namespace
xiyuan 2011/10/27 22:51:29 Done.
33
34 // static
35 AppListWindow* AppListWindow::instance_ = NULL;
36
37 AppListWindow::AppListWindow()
38 : widget_(NULL),
39 contents_(NULL) {
40 }
41
42 AppListWindow::~AppListWindow() {
43 }
44
45 void AppListWindow::DeleteDelegate() {
46 delete this;
47 }
48
49 views::View* AppListWindow::GetContentsView() {
50 return contents_;
51 }
52
53 void AppListWindow::WindowClosing() {
54 aura::Desktop::GetInstance()->RemoveObserver(this);
55 widget_ = NULL;
56 instance_ = NULL;
57 }
58
59 views::Widget* AppListWindow::GetWidget() {
60 return widget_;
61 }
62
63 const views::Widget* AppListWindow::GetWidget() const {
64 return widget_;
65 }
66
67 void AppListWindow::AnimationEnded(const ui::Animation* animation) {
68 if (animation_->GetCurrentValue() == 0)
69 widget_->Hide();
70 }
71
72 void AppListWindow::AnimationProgressed(const ui::Animation* animation) {
73 SetAnimationProgress(animation_->GetCurrentValue());
74 }
75
76 void AppListWindow::OnActiveWindowChanged(aura::Window* active) {
77 if (widget_ && !widget_->IsActive() && IsShowing())
78 Show(false /* show */, true /* animate */);
79 }
80
81 void AppListWindow::Init() {
82 DCHECK(!widget_ && !contents_);
83
84 contents_ = new DOMView();
85 contents_->Init(ProfileManager::GetDefaultProfile(), NULL);
86 contents_->LoadURL(GURL("chrome://newtab#applist"));
87
88 // Use a background with transparency to trigger transparent webkit.
89 SkBitmap background;
90 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
91 background.allocPixels();
92 background.eraseARGB(0x00, 0x00, 0x00, 0x00);
93
94 TabContents* tab = contents_->dom_contents()->tab_contents();
95 RenderViewHost* host = tab->render_view_host();
96 host->view()->SetBackground(background);
97
98 views::Widget::InitParams widget_params(
99 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
100 widget_params.delegate = this;
101
102 widget_ = new views::Widget;
sky 2011/10/25 17:59:27 Users might go a long time before using the app li
xiyuan 2011/10/27 22:51:29 Done. Closes the window instead of hiding now.
103 widget_->Init(widget_params);
104 widget_->SetContentsView(contents_);
105
106 aura::Desktop::GetInstance()->AddObserver(this);
107 }
108
109 void AppListWindow::Show(bool show, bool animated) {
110 if (animated) {
111 if (!animation_.get()) {
112 animation_.reset(new ui::SlideAnimation(this));
sky 2011/10/25 17:59:27 You should be able to accomplish both of these by
xiyuan 2011/10/27 22:51:29 Sort of done. Added a TODO to properly close windo
113 animation_->SetSlideDuration(kAnimationDurationMS);
114 animation_->Reset(show ? 0.0 : 1.0);
115 SetAnimationProgress(animation_->GetCurrentValue());
116 }
117
118 if (show) {
119 widget_->Activate();
120 widget_->Show();
121 animation_->Show();
122 } else {
123 animation_->Hide();
124 }
125 } else {
126 SetAnimationProgress(1.0);
127
128 if (show) {
129 widget_->Activate();
130 widget_->Show();
131 } else {
132 widget_->Hide();
133 }
134 }
135 }
136
137 bool AppListWindow::IsShowing() const {
138 if (animation_.get() && animation_->is_animating()) {
139 return animation_->IsShowing();
140 } else {
141 return widget_->IsVisible();
142 }
143 }
144
145 void AppListWindow::SetAnimationProgress(double progress) {
146 widget_->SetOpacity(progress * 255);
147
148 gfx::Rect frame = GetPreferredPosition();
149 frame.Offset(0, kMoveUpAnimationOffset * (1.0 - progress));
150 widget_->SetBounds(frame);
151 }
152
153 // static
154 void AppListWindow::Toggle() {
sky 2011/10/25 17:59:27 Make order of methods match order in header.
xiyuan 2011/10/27 22:51:29 Done.
155 if (!instance_) {
156 // TODO(xiyuan): Fix first time animation jankiness.
157 instance_ = new AppListWindow;
158 instance_->Init();
159 }
160
161 instance_->Show(!instance_->IsShowing(), true);
162 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/aura/app_list_window.h ('k') | chrome/browser/ui/views/aura/chrome_shell_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698