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/window_sizer/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/window_positioner.h" | 8 #include "ash/wm/window_positioner.h" |
9 #include "ash/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
15 | 15 |
16 bool WindowSizer::GetBrowserBoundsAsh(gfx::Rect* bounds, | 16 bool WindowSizer::GetBrowserBoundsAsh(gfx::Rect* bounds, |
17 ui::WindowShowState* show_state) const { | 17 ui::WindowShowState* show_state) const { |
18 if (!browser_ || | 18 if (!browser_ || |
19 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | 19 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) |
20 return false; | 20 return false; |
21 | 21 |
22 bool determined = false; | |
22 if (bounds->IsEmpty()) { | 23 if (bounds->IsEmpty()) { |
23 if (browser_->is_type_tabbed()) { | 24 if (browser_->is_type_tabbed()) { |
24 GetTabbedBrowserBoundsAsh(bounds, show_state); | 25 GetTabbedBrowserBoundsAsh(bounds, show_state); |
25 return true; | 26 determined = true; |
26 } | 27 } else if (browser_->is_trusted_source()) { |
27 | |
28 if (browser_->is_trusted_source()) { | |
29 // For trusted popups (v1 apps and system windows), do not use the last | 28 // For trusted popups (v1 apps and system windows), do not use the last |
30 // active window bounds, only use saved or default bounds. | 29 // active window bounds, only use saved or default bounds. |
31 if (!GetSavedWindowBounds(bounds, show_state)) | 30 if (!GetSavedWindowBounds(bounds, show_state)) |
32 GetDefaultWindowBounds(GetTargetDisplay(gfx::Rect()), bounds); | 31 GetDefaultWindowBounds(GetTargetDisplay(gfx::Rect()), bounds); |
33 return true; | 32 determined = true; |
33 } else { | |
34 // In Ash, prioritize the last saved |show_state|. If you have questions | |
35 // or comments about this behavior please contact oshima@chromium.org. | |
36 if (state_provider_) { | |
37 gfx::Rect ignored_bounds, ignored_work_area; | |
38 state_provider_->GetPersistentState(&ignored_bounds, | |
39 &ignored_work_area, | |
40 show_state); | |
41 } | |
34 } | 42 } |
35 | 43 } else { |
36 // In Ash, prioritize the last saved |show_state|. If you have questions | 44 // In case of a popup with an 'unspecified' location in ash, we are |
37 // or comments about this behavior please contact oshima@chromium.org. | 45 // looking for a good screen location. We are interpreting (0,0) as an |
38 if (state_provider_) { | 46 // unspecified location. |
39 gfx::Rect ignored_bounds, ignored_work_area; | 47 if (browser_->is_type_popup() && bounds->origin().IsOrigin()) { |
msw
2014/08/05 16:44:38
nit: combine this into an "else if" at line 43.
varkha
2014/08/05 17:55:23
Done.
| |
40 state_provider_->GetPersistentState(&ignored_bounds, | 48 *bounds = ash::Shell::GetInstance()->window_positioner()-> |
41 &ignored_work_area, | 49 GetPopupPosition(*bounds); |
42 show_state); | 50 determined = true; |
43 } | 51 } |
44 return false; | |
45 } | 52 } |
46 | 53 |
47 // In case of a popup with an 'unspecified' location in ash, we are | 54 if (*show_state == ui::SHOW_STATE_DEFAULT) { |
msw
2014/08/05 16:44:38
If this new behavior also applies to popup browser
varkha
2014/08/05 17:55:23
Makes sense to restrict this only to tabbed browse
| |
48 // looking for a good screen location. We are interpreting (0,0) as an | 55 gfx::Display display = screen_->GetDisplayMatching(*bounds); |
49 // unspecified location. | 56 gfx::Rect work_area = display.work_area(); |
50 if (browser_->is_type_popup() && bounds->origin().IsOrigin()) { | 57 bounds->AdjustToFit(work_area); |
51 *bounds = ash::Shell::GetInstance()->window_positioner()-> | 58 if (*bounds == work_area) { |
52 GetPopupPosition(*bounds); | 59 // A window that occupies the whole work area gets maximized. |
53 return true; | 60 // |bounds| returned here become the restore bounds once the window |
61 // gets maximized after this method returns. Return a sensible default | |
62 // in order to make restored state visibly different from maximized. | |
63 *show_state = ui::SHOW_STATE_MAXIMIZED; | |
64 *bounds = ash::WindowPositioner::GetDefaultWindowBounds(display); | |
65 determined = true; | |
66 } | |
54 } | 67 } |
55 return false; | 68 return determined; |
56 } | 69 } |
57 | 70 |
58 void WindowSizer::GetTabbedBrowserBoundsAsh( | 71 void WindowSizer::GetTabbedBrowserBoundsAsh( |
59 gfx::Rect* bounds_in_screen, | 72 gfx::Rect* bounds_in_screen, |
60 ui::WindowShowState* show_state) const { | 73 ui::WindowShowState* show_state) const { |
61 DCHECK(show_state); | 74 DCHECK(show_state); |
62 DCHECK(bounds_in_screen); | 75 DCHECK(bounds_in_screen); |
63 DCHECK(browser_->is_type_tabbed()); | 76 DCHECK(browser_->is_type_tabbed()); |
64 DCHECK(bounds_in_screen->IsEmpty()); | 77 DCHECK(bounds_in_screen->IsEmpty()); |
65 | 78 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 browser_->window() ? browser_->window()->GetNativeWindow() : NULL; | 111 browser_->window() ? browser_->window()->GetNativeWindow() : NULL; |
99 | 112 |
100 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow( | 113 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow( |
101 screen_, | 114 screen_, |
102 browser_window, | 115 browser_window, |
103 is_saved_bounds, | 116 is_saved_bounds, |
104 passed_show_state, | 117 passed_show_state, |
105 bounds_in_screen, | 118 bounds_in_screen, |
106 show_state); | 119 show_state); |
107 } | 120 } |
OLD | NEW |