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

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

Issue 17378003: [WIN]Save work area of window and adjust bounds to ensure it fit on screen before show. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and revise as comments. Created 7 years, 6 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
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 "apps/shell_window_geometry_cache.h" 7 #include "apps/shell_window_geometry_cache.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/app_window_contents.h" 10 #include "chrome/browser/extensions/app_window_contents.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 gfx::Rect bounds = params.bounds; 145 gfx::Rect bounds = params.bounds;
146 146
147 if (bounds.width() == 0) 147 if (bounds.width() == 0)
148 bounds.set_width(kDefaultWidth); 148 bounds.set_width(kDefaultWidth);
149 if (bounds.height() == 0) 149 if (bounds.height() == 0)
150 bounds.set_height(kDefaultHeight); 150 bounds.set_height(kDefaultHeight);
151 151
152 // If left and top are left undefined, the native shell window will center 152 // If left and top are left undefined, the native shell window will center
153 // the window on the main screen in a platform-defined manner. 153 // the window on the main screen in a platform-defined manner.
154 154
155 gfx::Rect cached_screen_bounds;
155 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; 156 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT;
156 if (!params.window_key.empty()) { 157 if (!params.window_key.empty()) {
157 window_key_ = params.window_key; 158 window_key_ = params.window_key;
158 159
159 apps::ShellWindowGeometryCache* cache = 160 apps::ShellWindowGeometryCache* cache =
160 apps::ShellWindowGeometryCache::Get(profile()); 161 apps::ShellWindowGeometryCache::Get(profile());
161 162
162 gfx::Rect cached_bounds; 163 gfx::Rect cached_bounds;
163 if (cache->GetGeometry(extension()->id(), params.window_key, 164 if (cache->GetGeometry(extension()->id(), params.window_key, &cached_bounds,
164 &cached_bounds, &cached_state)) { 165 &cached_screen_bounds, &cached_state)) {
165 bounds = cached_bounds; 166 bounds = cached_bounds;
166 } 167 }
167 } 168 }
168 169
169 CreateParams new_params = params; 170 CreateParams new_params = params;
170 171
171 gfx::Size& minimum_size = new_params.minimum_size; 172 gfx::Size& minimum_size = new_params.minimum_size;
172 gfx::Size& maximum_size = new_params.maximum_size; 173 gfx::Size& maximum_size = new_params.maximum_size;
173 174
174 // In the case that minimum size > maximum size, we consider the minimum 175 // In the case that minimum size > maximum size, we consider the minimum
(...skipping 13 matching lines...) Expand all
188 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) 189 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height())
189 bounds.set_height(minimum_size.height()); 190 bounds.set_height(minimum_size.height());
190 191
191 new_params.bounds = bounds; 192 new_params.bounds = bounds;
192 193
193 if (cached_state != ui::SHOW_STATE_DEFAULT) 194 if (cached_state != ui::SHOW_STATE_DEFAULT)
194 new_params.state = cached_state; 195 new_params.state = cached_state;
195 196
196 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); 197 native_app_window_.reset(NativeAppWindow::Create(this, new_params));
197 198
199 // App window has cached screen bounds, make sure it fits on screen in case of
scheib 2013/06/20 00:09:59 Please add that explanation to the comment here.
zhchbin 2013/06/20 06:50:52 Done.
200 // the screen resolution changed before show.
201 if (!cached_screen_bounds.IsEmpty()) {
202 gfx::Rect new_bounds;
203 gfx::Rect current_screen_bounds = native_app_window_->GetScreenBounds();
204 AdjustBoundsToBeVisibleOnScreen(bounds,
205 cached_screen_bounds,
206 current_screen_bounds,
207 minimum_size,
208 &new_bounds);
209 native_app_window_->SetBounds(new_bounds);
210 }
198 if (!new_params.hidden) { 211 if (!new_params.hidden) {
199 if (window_type_is_panel()) 212 if (window_type_is_panel())
200 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. 213 GetBaseWindow()->ShowInactive(); // Panels are not activated by default.
201 else 214 else
202 GetBaseWindow()->Show(); 215 GetBaseWindow()->Show();
203 } 216 }
204 217
205 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) 218 if (new_params.state == ui::SHOW_STATE_FULLSCREEN)
206 Fullscreen(); 219 Fullscreen();
207 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) 220 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED)
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 if (window_key_.empty()) 624 if (window_key_.empty())
612 return; 625 return;
613 if (!native_app_window_) 626 if (!native_app_window_)
614 return; 627 return;
615 628
616 apps::ShellWindowGeometryCache* cache = 629 apps::ShellWindowGeometryCache* cache =
617 apps::ShellWindowGeometryCache::Get(profile()); 630 apps::ShellWindowGeometryCache::Get(profile());
618 631
619 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); 632 gfx::Rect bounds = native_app_window_->GetRestoredBounds();
620 bounds.Inset(native_app_window_->GetFrameInsets()); 633 bounds.Inset(native_app_window_->GetFrameInsets());
634 gfx::Rect screen_bounds = native_app_window_->GetScreenBounds();
621 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); 635 ui::WindowShowState window_state = native_app_window_->GetRestoredState();
622 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); 636 cache->SaveGeometry(extension()->id(),
637 window_key_,
638 bounds,
639 screen_bounds,
640 window_state);
623 } 641 }
624 642
643 void ShellWindow::AdjustBoundsToBeVisibleOnScreen(
scheib 2013/06/20 00:09:59 Please add tests for AdjustBoundsToBeVisibleOnScre
zhchbin 2013/06/20 06:50:52 I had integrated it into the platform_app_browsert
644 const gfx::Rect& cached_bounds,
645 const gfx::Rect& cached_screen_bounds,
646 const gfx::Rect& current_screen_bounds,
647 const gfx::Size& minimum_size,
648 gfx::Rect* bounds) const {
649 if (!native_app_window_)
650 return;
651 if (!bounds)
652 return;
653
654 *bounds = cached_bounds;
655
656 // Reposition and resize the bounds if the cached_screen_bounds is different
657 // from the current screen bounds and the current screen bounds doesn't
658 // completely contain the bounds.
659 if (!cached_screen_bounds.IsEmpty() &&
660 cached_screen_bounds != current_screen_bounds &&
661 !current_screen_bounds.Contains(cached_bounds)) {
662 bounds->set_width(
663 std::max(minimum_size.width(),
664 std::min(bounds->width(), current_screen_bounds.width())));
665 bounds->set_height(
666 std::max(minimum_size.height(),
667 std::min(bounds->height(), current_screen_bounds.height())));
668 bounds->set_x(
669 std::max(current_screen_bounds.x(),
670 std::min(bounds->x(),
671 current_screen_bounds.right() - bounds->width())));
672 bounds->set_y(
673 std::max(current_screen_bounds.y(),
674 std::min(bounds->y(),
675 current_screen_bounds.bottom() - bounds->height())));
676 }
677 }
678
679
625 // static 680 // static
626 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( 681 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
627 const std::vector<extensions::DraggableRegion>& regions) { 682 const std::vector<extensions::DraggableRegion>& regions) {
628 SkRegion* sk_region = new SkRegion; 683 SkRegion* sk_region = new SkRegion;
629 for (std::vector<extensions::DraggableRegion>::const_iterator iter = 684 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
630 regions.begin(); 685 regions.begin();
631 iter != regions.end(); ++iter) { 686 iter != regions.end(); ++iter) {
632 const extensions::DraggableRegion& region = *iter; 687 const extensions::DraggableRegion& region = *iter;
633 sk_region->op( 688 sk_region->op(
634 region.bounds.x(), 689 region.bounds.x(),
635 region.bounds.y(), 690 region.bounds.y(),
636 region.bounds.right(), 691 region.bounds.right(),
637 region.bounds.bottom(), 692 region.bounds.bottom(),
638 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); 693 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
639 } 694 }
640 return sk_region; 695 return sk_region;
641 } 696 }
642 697
643 void ShellWindow::DisableExternalOpenForTesting() { 698 void ShellWindow::DisableExternalOpenForTesting() {
644 disable_external_open_for_testing_ = true; 699 disable_external_open_for_testing_ = true;
645 } 700 }
646 701
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698