OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/aura/app_list_window.h" | 5 #include "chrome/browser/ui/views/aura/app_list_window.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
8 #include "chrome/browser/ui/views/dom_view.h" | 8 #include "chrome/browser/ui/views/dom_view.h" |
| 9 #include "chrome/browser/ui/webui/aura/app_list_ui.h" |
9 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
10 #include "content/browser/renderer_host/render_view_host.h" | 11 #include "content/browser/renderer_host/render_view_host.h" |
11 #include "content/browser/renderer_host/render_widget_host_view.h" | 12 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 13 #include "ui/aura_shell/shell.h" |
12 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
13 | 15 |
14 AppListWindow::AppListWindow( | 16 AppListWindow::AppListWindow(const gfx::Rect& bounds, |
15 const aura_shell::ShellDelegate::SetWidgetCallback& callback) | 17 const aura_shell::ShellDelegate::SetWidgetCallback& callback) |
16 : widget_(NULL), | 18 : widget_(NULL), |
17 contents_(NULL), | 19 contents_(NULL), |
18 callback_(callback) { | 20 callback_(callback), |
19 Init(); | 21 content_rendered_(false), |
| 22 apps_loaded_(false) { |
| 23 Init(bounds); |
20 } | 24 } |
21 | 25 |
22 AppListWindow::~AppListWindow() { | 26 AppListWindow::~AppListWindow() { |
23 } | 27 } |
24 | 28 |
25 void AppListWindow::DeleteDelegate() { | 29 void AppListWindow::DeleteDelegate() { |
26 delete this; | 30 delete this; |
27 } | 31 } |
28 | 32 |
29 views::View* AppListWindow::GetContentsView() { | 33 views::View* AppListWindow::GetInitiallyFocusedView() { |
30 return contents_; | 34 return contents_; |
31 } | 35 } |
32 | 36 |
33 views::Widget* AppListWindow::GetWidget() { | 37 views::Widget* AppListWindow::GetWidget() { |
34 return widget_; | 38 return widget_; |
35 } | 39 } |
36 | 40 |
37 const views::Widget* AppListWindow::GetWidget() const { | 41 const views::Widget* AppListWindow::GetWidget() const { |
38 return widget_; | 42 return widget_; |
39 } | 43 } |
40 | 44 |
| 45 bool AppListWindow::HandleContextMenu(const ContextMenuParams& params) { |
| 46 // Do not show the context menu for non-debug build. |
| 47 #if !defined(NDEBUG) |
| 48 return false; |
| 49 #else |
| 50 return true; |
| 51 #endif |
| 52 } |
| 53 |
| 54 void AppListWindow::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 55 if (event.windowsKeyCode == ui::VKEY_ESCAPE) |
| 56 Close(); |
| 57 } |
| 58 |
| 59 bool AppListWindow::TakeFocus(bool reverse) { |
| 60 // Forward the focus back to web contents. |
| 61 contents_->dom_contents()->tab_contents()->FocusThroughTabTraversal(reverse); |
| 62 return true; |
| 63 } |
| 64 |
| 65 bool AppListWindow::IsPopupOrPanel(const TabContents* source) const { |
| 66 return true; |
| 67 } |
| 68 |
41 void AppListWindow::OnRenderHostCreated(RenderViewHost* host) { | 69 void AppListWindow::OnRenderHostCreated(RenderViewHost* host) { |
42 } | 70 } |
43 | 71 |
44 void AppListWindow::OnTabMainFrameLoaded() { | 72 void AppListWindow::OnTabMainFrameLoaded() { |
45 } | 73 } |
46 | 74 |
47 void AppListWindow::OnTabMainFrameFirstRender() { | 75 void AppListWindow::OnTabMainFrameFirstRender() { |
48 callback_.Run(widget_); | 76 content_rendered_ = true; |
| 77 SetWidgetIfReady(); |
49 } | 78 } |
50 | 79 |
51 void AppListWindow::Init() { | 80 void AppListWindow::Close() { |
| 81 // We should be visible when running here and toggle actually closes us. |
| 82 aura_shell::Shell::GetInstance()->ToggleAppList(); |
| 83 } |
| 84 |
| 85 void AppListWindow::OnAppsLoaded() { |
| 86 apps_loaded_ = true; |
| 87 SetWidgetIfReady(); |
| 88 } |
| 89 |
| 90 void AppListWindow::Init(const gfx::Rect& bounds) { |
52 DCHECK(!widget_ && !contents_); | 91 DCHECK(!widget_ && !contents_); |
53 | 92 |
54 contents_ = new DOMView(); | 93 contents_ = new DOMView(); |
55 contents_->Init(ProfileManager::GetDefaultProfile(), NULL); | 94 contents_->Init(ProfileManager::GetDefaultProfile(), NULL); |
56 | 95 |
57 TabContents* tab = contents_->dom_contents()->tab_contents(); | 96 TabContents* tab = contents_->dom_contents()->tab_contents(); |
58 tab_watcher_.reset(new TabFirstRenderWatcher(tab, this)); | 97 tab_watcher_.reset(new TabFirstRenderWatcher(tab, this)); |
| 98 tab->set_delegate(this); |
59 | 99 |
60 contents_->LoadURL(GURL(chrome::kChromeUIAppListURL)); | 100 contents_->LoadURL(GURL(chrome::kChromeUIAppListURL)); |
| 101 static_cast<AppListUI*>(tab->web_ui())->set_delegate(this); |
61 | 102 |
62 // Use a background with transparency to trigger transparent webkit. | 103 // Use a background with transparency to trigger transparent webkit. |
63 SkBitmap background; | 104 SkBitmap background; |
64 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 105 background.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
65 background.allocPixels(); | 106 background.allocPixels(); |
66 background.eraseARGB(0x00, 0x00, 0x00, 0x00); | 107 background.eraseARGB(0x00, 0x00, 0x00, 0x00); |
67 | 108 |
68 RenderViewHost* host = tab->render_view_host(); | 109 RenderViewHost* host = tab->render_view_host(); |
69 host->view()->SetBackground(background); | 110 host->view()->SetBackground(background); |
70 | 111 |
71 views::Widget::InitParams widget_params( | 112 views::Widget::InitParams widget_params( |
72 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 113 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
73 // A non-empty bounds so that we get rendered notification. Make the size | 114 widget_params.bounds = bounds; |
74 // close the final size so that card slider resize handler does no generate | |
75 // unexpected animation. | |
76 widget_params.bounds = gfx::Rect(0, 0, 900, 700); | |
77 widget_params.delegate = this; | 115 widget_params.delegate = this; |
78 widget_params.keep_on_top = true; | 116 widget_params.keep_on_top = true; |
79 widget_params.transparent = true; | 117 widget_params.transparent = true; |
80 | 118 |
81 widget_ = new views::Widget; | 119 widget_ = new views::Widget; |
82 widget_->Init(widget_params); | 120 widget_->Init(widget_params); |
83 widget_->SetContentsView(contents_); | 121 widget_->SetContentsView(contents_); |
84 } | 122 } |
| 123 |
| 124 void AppListWindow::SetWidgetIfReady() { |
| 125 if (content_rendered_ && apps_loaded_) |
| 126 callback_.Run(widget_); |
| 127 } |
OLD | NEW |