Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / window_sizer / window_sizer_ash.cc
blob7c6da18dafa611c79b7e1971c5f3e2fc83af22e0
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/window_sizer/window_sizer.h"
7 #include "ash/shell.h"
8 #include "ash/wm/window_positioner.h"
9 #include "ash/wm/window_state.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "ui/aura/window.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/gfx/screen.h"
16 bool WindowSizer::GetBrowserBoundsAsh(gfx::Rect* bounds,
17 ui::WindowShowState* show_state) const {
18 if (!browser_ ||
19 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
20 return false;
22 if (bounds->IsEmpty()) {
23 if (browser_->is_type_tabbed()) {
24 GetTabbedBrowserBoundsAsh(bounds, show_state);
25 return true;
28 if (browser_->is_trusted_source()) {
29 // For trusted popups (v1 apps and system windows), do not use the last
30 // active window bounds, only use saved or default bounds.
31 if (!GetSavedWindowBounds(bounds, show_state))
32 GetDefaultWindowBounds(GetTargetDisplay(gfx::Rect()), bounds);
33 return true;
36 // In Ash, prioritize the last saved |show_state|. If you have questions
37 // or comments about this behavior please contact oshima@chromium.org.
38 if (state_provider_) {
39 gfx::Rect ignored_bounds, ignored_work_area;
40 state_provider_->GetPersistentState(&ignored_bounds,
41 &ignored_work_area,
42 show_state);
44 return false;
47 // In case of a popup with an 'unspecified' location in ash, we are
48 // looking for a good screen location. We are interpreting (0,0) as an
49 // unspecified location.
50 if (browser_->is_type_popup() && bounds->origin().IsOrigin()) {
51 *bounds = ash::Shell::GetInstance()->window_positioner()->
52 GetPopupPosition(*bounds);
53 return true;
55 return false;
58 void WindowSizer::GetTabbedBrowserBoundsAsh(
59 gfx::Rect* bounds_in_screen,
60 ui::WindowShowState* show_state) const {
61 DCHECK(show_state);
62 DCHECK(bounds_in_screen);
63 DCHECK(browser_->is_type_tabbed());
64 DCHECK(bounds_in_screen->IsEmpty());
66 ui::WindowShowState passed_show_state = *show_state;
68 bool is_saved_bounds = GetSavedWindowBounds(bounds_in_screen, show_state);
69 gfx::Display display;
70 if (is_saved_bounds) {
71 display = screen_->GetDisplayMatching(*bounds_in_screen);
72 } else {
73 // If there is no saved bounds (hence bounds_in_screen is empty), use the
74 // target display.
75 display = target_display_provider_->GetTargetDisplay(screen_,
76 *bounds_in_screen);
77 *bounds_in_screen = ash::WindowPositioner::GetDefaultWindowBounds(display);
80 if (browser_->is_session_restore()) {
81 // This is a fall-through case when there is no bounds recorded
82 // for restored window, and should not be used except for the case
83 // above. The regular path is handled in
84 // |WindowSizer::DetermineWindowBoundsAndShowState|.
86 // Note: How restore bounds/show state data are passed.
87 // The restore bounds is passed via |Browser::override_bounds()| in
88 // |chrome::GetBrowserWindowBoundsAndShowState()|.
89 // The restore state is passed via |Browser::initial_state()| in
90 // |WindowSizer::GetWindowDefaultShowState|.
91 bounds_in_screen->AdjustToFit(display.work_area());
92 return;
95 // The |browser_window| is non NULL when this is called after
96 // browser's aura window is created.
97 aura::Window* browser_window =
98 browser_->window() ? browser_->window()->GetNativeWindow() : NULL;
100 ash::WindowPositioner::GetBoundsAndShowStateForNewWindow(
101 screen_,
102 browser_window,
103 is_saved_bounds,
104 passed_show_state,
105 bounds_in_screen,
106 show_state);