OLD | NEW |
---|---|
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 Loading... | |
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_work_area; | |
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, |
164 &cached_bounds, &cached_state)) { | 165 &cached_bounds, &cached_work_area, &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 Loading... | |
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 work area, make sure it fits on screen in case of the | |
scheib
2013/06/18 21:52:06
Why not place this above, before new_params.bounds
zhchbin
2013/06/19 05:43:32
Because in the AdjustBoundsToBeVisibleOnMonitorCon
| |
200 // screen resolution changed before show. | |
201 if (!cached_work_area.IsEmpty()) { | |
202 gfx::Rect new_bounds; | |
203 AdjustBoundsToBeVisibleOnMonitorContaining(bounds, cached_work_area, | |
204 &new_bounds); | |
205 native_app_window_->SetBounds(new_bounds); | |
206 } | |
198 if (!new_params.hidden) { | 207 if (!new_params.hidden) { |
199 if (window_type_is_panel()) | 208 if (window_type_is_panel()) |
200 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | 209 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. |
201 else | 210 else |
202 GetBaseWindow()->Show(); | 211 GetBaseWindow()->Show(); |
203 } | 212 } |
204 | 213 |
205 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) | 214 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) |
206 Fullscreen(); | 215 Fullscreen(); |
207 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) | 216 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 if (window_key_.empty()) | 619 if (window_key_.empty()) |
611 return; | 620 return; |
612 if (!native_app_window_) | 621 if (!native_app_window_) |
613 return; | 622 return; |
614 | 623 |
615 apps::ShellWindowGeometryCache* cache = | 624 apps::ShellWindowGeometryCache* cache = |
616 apps::ShellWindowGeometryCache::Get(profile()); | 625 apps::ShellWindowGeometryCache::Get(profile()); |
617 | 626 |
618 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 627 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
619 bounds.Inset(native_app_window_->GetFrameInsets()); | 628 bounds.Inset(native_app_window_->GetFrameInsets()); |
629 gfx::Rect work_area = native_app_window_->GetWindowWorkArea(); | |
620 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); | 630 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
621 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); | 631 cache->SaveGeometry(extension()->id(), |
632 window_key_, | |
633 bounds, | |
634 work_area, | |
635 window_state); | |
622 } | 636 } |
623 | 637 |
638 void ShellWindow::AdjustBoundsToBeVisibleOnMonitorContaining( | |
scheib
2013/06/18 21:52:06
Monitor is inconsistent with naming elsewhere. 'Wo
scheib
2013/06/18 21:52:06
Please add several tests for this function, for sh
zhchbin
2013/06/20 06:35:50
Done.
zhchbin
2013/06/20 06:35:50
Done.
| |
639 const gfx::Rect& cached_bounds, | |
640 const gfx::Rect& cached_work_area, | |
641 gfx::Rect* bounds) const { | |
642 if (!native_app_window_) | |
643 return; | |
644 if (!bounds) | |
645 return; | |
646 | |
647 *bounds = cached_bounds; | |
648 gfx::Rect work_area = native_app_window_->GetWindowWorkArea(); | |
649 | |
650 // Reposition and resize the bounds if the saved_work_area is different from | |
651 // the current work area and the current work area doesn't completely contain | |
652 // the bounds. | |
653 if (!cached_work_area.IsEmpty() && | |
654 cached_work_area != work_area && | |
655 !work_area.Contains(cached_bounds)) { | |
656 bounds->set_width(std::min(bounds->width(), work_area.width())); | |
scheib
2013/06/18 21:52:06
We can not resize to a smaller window than minimum
zhchbin
2013/06/20 06:35:50
Done.
| |
657 bounds->set_height(std::min(bounds->height(), work_area.height())); | |
658 bounds->set_x( | |
659 std::max(work_area.x(), | |
660 std::min(bounds->x(), work_area.right() - bounds->width()))); | |
661 bounds->set_y( | |
662 std::max(work_area.y(), | |
663 std::min(bounds->y(), work_area.bottom() - bounds->height()))); | |
664 } | |
665 } | |
666 | |
667 | |
624 // static | 668 // static |
625 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( | 669 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( |
626 const std::vector<extensions::DraggableRegion>& regions) { | 670 const std::vector<extensions::DraggableRegion>& regions) { |
627 SkRegion* sk_region = new SkRegion; | 671 SkRegion* sk_region = new SkRegion; |
628 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 672 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
629 regions.begin(); | 673 regions.begin(); |
630 iter != regions.end(); ++iter) { | 674 iter != regions.end(); ++iter) { |
631 const extensions::DraggableRegion& region = *iter; | 675 const extensions::DraggableRegion& region = *iter; |
632 sk_region->op( | 676 sk_region->op( |
633 region.bounds.x(), | 677 region.bounds.x(), |
634 region.bounds.y(), | 678 region.bounds.y(), |
635 region.bounds.right(), | 679 region.bounds.right(), |
636 region.bounds.bottom(), | 680 region.bounds.bottom(), |
637 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 681 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
638 } | 682 } |
639 return sk_region; | 683 return sk_region; |
640 } | 684 } |
641 | 685 |
642 void ShellWindow::DisableExternalOpenForTesting() { | 686 void ShellWindow::DisableExternalOpenForTesting() { |
643 disable_external_open_for_testing_ = true; | 687 disable_external_open_for_testing_ = true; |
644 } | 688 } |
645 | 689 |
OLD | NEW |