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