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

Side by Side Diff: chrome/browser/ui/extensions/shell_window.cc

Issue 14031021: Save and restore State for ShellWindows, including panels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/extensions/shell_window.h" 5 #include "chrome/browser/ui/extensions/shell_window.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/app_window_contents.h" 9 #include "chrome/browser/extensions/app_window_contents.h"
10 #include "chrome/browser/extensions/extension_process_manager.h" 10 #include "chrome/browser/extensions/extension_process_manager.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #endif 65 #endif
66 66
67 } // namespace 67 } // namespace
68 68
69 ShellWindow::CreateParams::CreateParams() 69 ShellWindow::CreateParams::CreateParams()
70 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), 70 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT),
71 frame(ShellWindow::FRAME_CHROME), 71 frame(ShellWindow::FRAME_CHROME),
72 transparent_background(false), 72 transparent_background(false),
73 bounds(INT_MIN, INT_MIN, 0, 0), 73 bounds(INT_MIN, INT_MIN, 0, 0),
74 creator_process_id(0), 74 creator_process_id(0),
75 state(STATE_NORMAL), 75 state(ui::SHOW_STATE_DEFAULT),
76 hidden(false), 76 hidden(false),
77 resizable(true), 77 resizable(true),
78 focused(true) { 78 focused(true) {
79 } 79 }
80 80
81 ShellWindow::CreateParams::~CreateParams() { 81 ShellWindow::CreateParams::~CreateParams() {
82 } 82 }
83 83
84 ShellWindow* ShellWindow::Create(Profile* profile, 84 ShellWindow* ShellWindow::Create(Profile* profile,
85 const extensions::Extension* extension, 85 const extensions::Extension* extension,
(...skipping 11 matching lines...) Expand all
97 : profile_(profile), 97 : profile_(profile),
98 extension_(extension), 98 extension_(extension),
99 window_type_(WINDOW_TYPE_DEFAULT), 99 window_type_(WINDOW_TYPE_DEFAULT),
100 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)), 100 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)),
101 fullscreen_for_window_api_(false), 101 fullscreen_for_window_api_(false),
102 fullscreen_for_tab_(false) { 102 fullscreen_for_tab_(false) {
103 } 103 }
104 104
105 void ShellWindow::Init(const GURL& url, 105 void ShellWindow::Init(const GURL& url,
106 ShellWindowContents* shell_window_contents, 106 ShellWindowContents* shell_window_contents,
107 const ShellWindow::CreateParams& params) { 107 const CreateParams& params) {
108 // Initialize the render interface and web contents 108 // Initialize the render interface and web contents
109 shell_window_contents_.reset(shell_window_contents); 109 shell_window_contents_.reset(shell_window_contents);
110 shell_window_contents_->Initialize(profile(), url); 110 shell_window_contents_->Initialize(profile(), url);
111 WebContents* web_contents = shell_window_contents_->GetWebContents(); 111 WebContents* web_contents = shell_window_contents_->GetWebContents();
112 WebContentsModalDialogManager::CreateForWebContents(web_contents); 112 WebContentsModalDialogManager::CreateForWebContents(web_contents);
113 FaviconTabHelper::CreateForWebContents(web_contents); 113 FaviconTabHelper::CreateForWebContents(web_contents);
114 114
115 web_contents->SetDelegate(this); 115 web_contents->SetDelegate(this);
116 WebContentsModalDialogManager::FromWebContents(web_contents)-> 116 WebContentsModalDialogManager::FromWebContents(web_contents)->
117 set_delegate(this); 117 set_delegate(this);
118 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); 118 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL);
119 119
120 // Initialize the window 120 // Initialize the window
121 window_type_ = params.window_type; 121 window_type_ = params.window_type;
122 122
123 gfx::Rect bounds = params.bounds; 123 gfx::Rect bounds = params.bounds;
124 124
125 if (bounds.width() == 0) 125 if (bounds.width() == 0)
126 bounds.set_width(kDefaultWidth); 126 bounds.set_width(kDefaultWidth);
127 if (bounds.height() == 0) 127 if (bounds.height() == 0)
128 bounds.set_height(kDefaultHeight); 128 bounds.set_height(kDefaultHeight);
129 129
130 // If left and top are left undefined, the native shell window will center 130 // If left and top are left undefined, the native shell window will center
131 // the window on the main screen in a platform-defined manner. 131 // the window on the main screen in a platform-defined manner.
132 132
133 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
133 if (!params.window_key.empty()) { 134 if (!params.window_key.empty()) {
134 window_key_ = params.window_key; 135 window_key_ = params.window_key;
135 136
136 extensions::ShellWindowGeometryCache* cache = 137 extensions::ShellWindowGeometryCache* cache =
137 extensions::ExtensionSystem::Get(profile())-> 138 extensions::ExtensionSystem::Get(profile())->
138 shell_window_geometry_cache(); 139 shell_window_geometry_cache();
139 gfx::Rect cached_bounds; 140 gfx::Rect cached_bounds;
140 if (cache->GetGeometry(extension()->id(), params.window_key, 141 if (cache->GetGeometry(extension()->id(), params.window_key,
141 &cached_bounds)) 142 &cached_bounds, &cached_state)) {
142 bounds = cached_bounds; 143 bounds = cached_bounds;
144 }
143 } 145 }
144 146
145 ShellWindow::CreateParams new_params = params; 147 CreateParams new_params = params;
146 148
147 gfx::Size& minimum_size = new_params.minimum_size; 149 gfx::Size& minimum_size = new_params.minimum_size;
148 gfx::Size& maximum_size = new_params.maximum_size; 150 gfx::Size& maximum_size = new_params.maximum_size;
149 151
150 // In the case that minimum size > maximum size, we consider the minimum 152 // In the case that minimum size > maximum size, we consider the minimum
151 // size to be more important. 153 // size to be more important.
152 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) 154 if (maximum_size.width() && maximum_size.width() < minimum_size.width())
153 maximum_size.set_width(minimum_size.width()); 155 maximum_size.set_width(minimum_size.width());
154 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) 156 if (maximum_size.height() && maximum_size.height() < minimum_size.height())
155 maximum_size.set_height(minimum_size.height()); 157 maximum_size.set_height(minimum_size.height());
156 158
157 if (maximum_size.width() && bounds.width() > maximum_size.width()) 159 if (maximum_size.width() && bounds.width() > maximum_size.width())
158 bounds.set_width(maximum_size.width()); 160 bounds.set_width(maximum_size.width());
159 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) 161 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width())
160 bounds.set_width(minimum_size.width()); 162 bounds.set_width(minimum_size.width());
161 163
162 if (maximum_size.height() && bounds.height() > maximum_size.height()) 164 if (maximum_size.height() && bounds.height() > maximum_size.height())
163 bounds.set_height(maximum_size.height()); 165 bounds.set_height(maximum_size.height());
164 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) 166 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height())
165 bounds.set_height(minimum_size.height()); 167 bounds.set_height(minimum_size.height());
166 168
167 new_params.bounds = bounds; 169 new_params.bounds = bounds;
168 170
171 if (cached_state != ui::SHOW_STATE_DEFAULT)
172 new_params.state = cached_state;
173
169 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); 174 native_app_window_.reset(NativeAppWindow::Create(this, new_params));
170 OnNativeWindowChanged(); 175 OnNativeWindowChanged();
171 176
172 switch (params.state) { 177 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
173 case CreateParams::STATE_NORMAL: 178 Fullscreen();
174 break; 179 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED)
175 case CreateParams::STATE_FULLSCREEN: 180 Maximize();
176 Fullscreen(); 181 else if (new_params.state == ui::SHOW_STATE_MINIMIZED)
177 break; 182 Minimize();
178 case CreateParams::STATE_MAXIMIZED:
179 Maximize();
180 break;
181 case CreateParams::STATE_MINIMIZED:
182 Minimize();
183 break;
184 }
185 183
186 if (!params.hidden) { 184 if (!params.hidden) {
187 if (window_type_is_panel()) 185 if (window_type_is_panel())
188 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. 186 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
189 else 187 else
190 GetBaseWindow()->Show(); 188 GetBaseWindow()->Show();
191 } 189 }
192 190
193 // When the render view host is changed, the native window needs to know 191 // When the render view host is changed, the native window needs to know
194 // about it in case it has any setup to do to make the renderer appear 192 // about it in case it has any setup to do to make the renderer appear
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return; 560 return;
563 if (!native_app_window_) 561 if (!native_app_window_)
564 return; 562 return;
565 563
566 extensions::ShellWindowGeometryCache* cache = 564 extensions::ShellWindowGeometryCache* cache =
567 extensions::ExtensionSystem::Get(profile())-> 565 extensions::ExtensionSystem::Get(profile())->
568 shell_window_geometry_cache(); 566 shell_window_geometry_cache();
569 567
570 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); 568 gfx::Rect bounds = native_app_window_->GetRestoredBounds();
571 bounds.Inset(native_app_window_->GetFrameInsets()); 569 bounds.Inset(native_app_window_->GetFrameInsets());
572 cache->SaveGeometry(extension()->id(), window_key_, bounds); 570 ui::WindowShowState window_state;
571 if (GetBaseWindow()->IsFullscreen())
572 window_state = ui::SHOW_STATE_FULLSCREEN;
573 else if (GetBaseWindow()->IsMaximized())
574 window_state = ui::SHOW_STATE_MAXIMIZED;
575 else if (GetBaseWindow()->IsMinimized())
576 window_state = ui::SHOW_STATE_MINIMIZED;
577 else if (GetBaseWindow()->IsDetached())
578 window_state = ui::SHOW_STATE_DETACHED;
579 else
580 window_state = ui::SHOW_STATE_NORMAL;
581 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state);
573 } 582 }
574 583
575 // static 584 // static
576 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( 585 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
577 const std::vector<extensions::DraggableRegion>& regions) { 586 const std::vector<extensions::DraggableRegion>& regions) {
578 SkRegion* sk_region = new SkRegion; 587 SkRegion* sk_region = new SkRegion;
579 for (std::vector<extensions::DraggableRegion>::const_iterator iter = 588 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
580 regions.begin(); 589 regions.begin();
581 iter != regions.end(); ++iter) { 590 iter != regions.end(); ++iter) {
582 const extensions::DraggableRegion& region = *iter; 591 const extensions::DraggableRegion& region = *iter;
583 sk_region->op( 592 sk_region->op(
584 region.bounds.x(), 593 region.bounds.x(),
585 region.bounds.y(), 594 region.bounds.y(),
586 region.bounds.right(), 595 region.bounds.right(),
587 region.bounds.bottom(), 596 region.bounds.bottom(),
588 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 597 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
589 } 598 }
590 return sk_region; 599 return sk_region;
591 } 600 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698