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/extensions/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 return ui::SHOW_STATE_MAXIMIZED; | 191 return ui::SHOW_STATE_MAXIMIZED; |
192 case windows::WINDOW_STATE_FULLSCREEN: | 192 case windows::WINDOW_STATE_FULLSCREEN: |
193 return ui::SHOW_STATE_FULLSCREEN; | 193 return ui::SHOW_STATE_FULLSCREEN; |
194 case windows::WINDOW_STATE_NONE: | 194 case windows::WINDOW_STATE_NONE: |
195 return ui::SHOW_STATE_DEFAULT; | 195 return ui::SHOW_STATE_DEFAULT; |
196 } | 196 } |
197 NOTREACHED(); | 197 NOTREACHED(); |
198 return ui::SHOW_STATE_DEFAULT; | 198 return ui::SHOW_STATE_DEFAULT; |
199 } | 199 } |
200 | 200 |
| 201 bool IsValidStateForWindowsCreateFunction( |
| 202 const windows::Create::Params::CreateData* create_data) { |
| 203 if (!create_data) |
| 204 return true; |
| 205 |
| 206 bool has_bound = create_data->left || create_data->top || |
| 207 create_data->width || create_data->height; |
| 208 bool is_panel = |
| 209 create_data->type == windows::CreateType::CREATE_TYPE_PANEL || |
| 210 create_data->type == windows::CreateType::CREATE_TYPE_DETACHED_PANEL; |
| 211 |
| 212 switch (create_data->state) { |
| 213 case windows::WINDOW_STATE_MINIMIZED: |
| 214 // If minimised, default focused state should be unfocused. |
| 215 return !(create_data->focused && *create_data->focused) && !has_bound && |
| 216 !is_panel; |
| 217 case windows::WINDOW_STATE_MAXIMIZED: |
| 218 case windows::WINDOW_STATE_FULLSCREEN: |
| 219 // If maximised/fullscreen, default focused state should be focused. |
| 220 return !(create_data->focused && !*create_data->focused) && !has_bound && |
| 221 !is_panel; |
| 222 case windows::WINDOW_STATE_NORMAL: |
| 223 case windows::WINDOW_STATE_NONE: |
| 224 return true; |
| 225 } |
| 226 NOTREACHED(); |
| 227 return true; |
| 228 } |
| 229 |
201 } // namespace | 230 } // namespace |
202 | 231 |
203 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, | 232 void ZoomModeToZoomSettings(ZoomController::ZoomMode zoom_mode, |
204 api::tabs::ZoomSettings* zoom_settings) { | 233 api::tabs::ZoomSettings* zoom_settings) { |
205 DCHECK(zoom_settings); | 234 DCHECK(zoom_settings); |
206 switch (zoom_mode) { | 235 switch (zoom_mode) { |
207 case ZoomController::ZOOM_MODE_DEFAULT: | 236 case ZoomController::ZOOM_MODE_DEFAULT: |
208 zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC; | 237 zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC; |
209 zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN; | 238 zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN; |
210 break; | 239 break; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 GetProfile(), | 443 GetProfile(), |
415 include_incognito(), | 444 include_incognito(), |
416 NULL, | 445 NULL, |
417 &source_tab_strip, | 446 &source_tab_strip, |
418 NULL, | 447 NULL, |
419 &tab_index, | 448 &tab_index, |
420 &error_)) | 449 &error_)) |
421 return false; | 450 return false; |
422 } | 451 } |
423 | 452 |
| 453 if (!IsValidStateForWindowsCreateFunction(create_data)) { |
| 454 error_ = keys::kInvalidWindowStateError; |
| 455 return false; |
| 456 } |
| 457 |
424 Profile* window_profile = GetProfile(); | 458 Profile* window_profile = GetProfile(); |
425 Browser::Type window_type = Browser::TYPE_TABBED; | 459 Browser::Type window_type = Browser::TYPE_TABBED; |
426 bool create_panel = false; | 460 bool create_panel = false; |
427 | 461 |
428 // panel_create_mode only applies if create_panel = true | 462 // panel_create_mode only applies if create_panel = true |
429 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; | 463 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; |
430 | 464 |
431 gfx::Rect window_bounds; | 465 gfx::Rect window_bounds; |
432 bool focused = true; | 466 bool focused = true; |
433 bool saw_focus_key = false; | 467 bool saw_focus_key = false; |
(...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2005 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
1972 zoom_settings.default_zoom_factor.reset(new double( | 2006 zoom_settings.default_zoom_factor.reset(new double( |
1973 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2007 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
1974 | 2008 |
1975 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2009 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
1976 SendResponse(true); | 2010 SendResponse(true); |
1977 return true; | 2011 return true; |
1978 } | 2012 } |
1979 | 2013 |
1980 } // namespace extensions | 2014 } // namespace extensions |
OLD | NEW |