| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/frame/browser_view.h" | 5 #include "chrome/browser/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 browser_(browser), | 202 browser_(browser), |
| 203 active_bookmark_bar_(NULL), | 203 active_bookmark_bar_(NULL), |
| 204 active_download_shelf_(NULL), | 204 active_download_shelf_(NULL), |
| 205 toolbar_(NULL), | 205 toolbar_(NULL), |
| 206 infobar_container_(NULL), | 206 infobar_container_(NULL), |
| 207 find_bar_y_(0), | 207 find_bar_y_(0), |
| 208 contents_container_(NULL), | 208 contents_container_(NULL), |
| 209 initialized_(false), | 209 initialized_(false), |
| 210 fullscreen_(false), | 210 fullscreen_(false), |
| 211 ignore_layout_(false), | 211 ignore_layout_(false), |
| 212 can_drop_(false), | |
| 213 hung_window_detector_(&hung_plugin_action_), | 212 hung_window_detector_(&hung_plugin_action_), |
| 214 ticker_(0), | 213 ticker_(0) |
| 215 #ifdef CHROME_PERSONALIZATION | 214 #ifdef CHROME_PERSONALIZATION |
| 216 personalization_enabled_(false), | 215 , personalization_enabled_(false), |
| 217 personalization_(NULL), | 216 personalization_(NULL) |
| 218 #endif | 217 #endif |
| 219 forwarding_to_tab_strip_(false) { | 218 { |
| 220 InitClass(); | 219 InitClass(); |
| 221 browser_->tabstrip_model()->AddObserver(this); | 220 browser_->tabstrip_model()->AddObserver(this); |
| 222 } | 221 } |
| 223 | 222 |
| 224 BrowserView::~BrowserView() { | 223 BrowserView::~BrowserView() { |
| 225 browser_->tabstrip_model()->RemoveObserver(this); | 224 browser_->tabstrip_model()->RemoveObserver(this); |
| 226 | 225 |
| 227 // Stop hung plugin monitoring. | 226 // Stop hung plugin monitoring. |
| 228 ticker_.Stop(); | 227 ticker_.Stop(); |
| 229 ticker_.UnregisterTickHandler(&hung_window_detector_); | 228 ticker_.UnregisterTickHandler(&hung_window_detector_); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 accelerator_table_->begin(); | 368 accelerator_table_->begin(); |
| 370 for (; it != accelerator_table_->end(); ++it) { | 369 for (; it != accelerator_table_->end(); ++it) { |
| 371 if (it->second == cmd_id) { | 370 if (it->second == cmd_id) { |
| 372 *accelerator = it->first; | 371 *accelerator = it->first; |
| 373 return true; | 372 return true; |
| 374 } | 373 } |
| 375 } | 374 } |
| 376 return false; | 375 return false; |
| 377 } | 376 } |
| 378 | 377 |
| 379 void BrowserView::AddViewToDropList(views::View* view) { | |
| 380 dropable_views_.insert(view); | |
| 381 } | |
| 382 | |
| 383 bool BrowserView::ActivateAppModalDialog() const { | 378 bool BrowserView::ActivateAppModalDialog() const { |
| 384 // If another browser is app modal, flash and activate the modal browser. | 379 // If another browser is app modal, flash and activate the modal browser. |
| 385 if (AppModalDialogQueue::HasActiveDialog()) { | 380 if (AppModalDialogQueue::HasActiveDialog()) { |
| 386 Browser* active_browser = BrowserList::GetLastActive(); | 381 Browser* active_browser = BrowserList::GetLastActive(); |
| 387 if (active_browser && (browser_ != active_browser)) { | 382 if (active_browser && (browser_ != active_browser)) { |
| 388 active_browser->window()->FlashFrame(); | 383 active_browser->window()->FlashFrame(); |
| 389 active_browser->window()->Activate(); | 384 active_browser->window()->Activate(); |
| 390 } | 385 } |
| 391 AppModalDialogQueue::ActivateModalDialog(); | 386 AppModalDialogQueue::ActivateModalDialog(); |
| 392 return true; | 387 return true; |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 SchedulePaint(); | 1249 SchedulePaint(); |
| 1255 } | 1250 } |
| 1256 | 1251 |
| 1257 void BrowserView::ViewHierarchyChanged(bool is_add, | 1252 void BrowserView::ViewHierarchyChanged(bool is_add, |
| 1258 views::View* parent, | 1253 views::View* parent, |
| 1259 views::View* child) { | 1254 views::View* child) { |
| 1260 if (is_add && child == this && GetWidget() && !initialized_) { | 1255 if (is_add && child == this && GetWidget() && !initialized_) { |
| 1261 Init(); | 1256 Init(); |
| 1262 initialized_ = true; | 1257 initialized_ = true; |
| 1263 } | 1258 } |
| 1264 if (!is_add) | |
| 1265 dropable_views_.erase(child); | |
| 1266 } | 1259 } |
| 1267 | 1260 |
| 1268 bool BrowserView::CanDrop(const OSExchangeData& data) { | |
| 1269 can_drop_ = (tabstrip_->IsVisible() && !tabstrip_->IsAnimating() && | |
| 1270 data.HasURL()); | |
| 1271 return can_drop_; | |
| 1272 } | |
| 1273 | |
| 1274 void BrowserView::OnDragEntered(const views::DropTargetEvent& event) { | |
| 1275 if (can_drop_ && ShouldForwardToTabStrip(event)) { | |
| 1276 forwarding_to_tab_strip_ = true; | |
| 1277 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1278 MapEventToTabStrip(event)); | |
| 1279 tabstrip_->OnDragEntered(*mapped_event.get()); | |
| 1280 } | |
| 1281 } | |
| 1282 | |
| 1283 int BrowserView::OnDragUpdated(const views::DropTargetEvent& event) { | |
| 1284 if (can_drop_) { | |
| 1285 if (ShouldForwardToTabStrip(event)) { | |
| 1286 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1287 MapEventToTabStrip(event)); | |
| 1288 if (!forwarding_to_tab_strip_) { | |
| 1289 tabstrip_->OnDragEntered(*mapped_event.get()); | |
| 1290 forwarding_to_tab_strip_ = true; | |
| 1291 } | |
| 1292 return tabstrip_->OnDragUpdated(*mapped_event.get()); | |
| 1293 } else if (forwarding_to_tab_strip_) { | |
| 1294 forwarding_to_tab_strip_ = false; | |
| 1295 tabstrip_->OnDragExited(); | |
| 1296 } | |
| 1297 } | |
| 1298 return DragDropTypes::DRAG_NONE; | |
| 1299 } | |
| 1300 | |
| 1301 void BrowserView::OnDragExited() { | |
| 1302 if (forwarding_to_tab_strip_) { | |
| 1303 forwarding_to_tab_strip_ = false; | |
| 1304 tabstrip_->OnDragExited(); | |
| 1305 } | |
| 1306 } | |
| 1307 | |
| 1308 int BrowserView::OnPerformDrop(const views::DropTargetEvent& event) { | |
| 1309 if (forwarding_to_tab_strip_) { | |
| 1310 forwarding_to_tab_strip_ = false; | |
| 1311 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1312 MapEventToTabStrip(event)); | |
| 1313 return tabstrip_->OnPerformDrop(*mapped_event.get()); | |
| 1314 } | |
| 1315 return DragDropTypes::DRAG_NONE; | |
| 1316 } | |
| 1317 | |
| 1318 | |
| 1319 /////////////////////////////////////////////////////////////////////////////// | 1261 /////////////////////////////////////////////////////////////////////////////// |
| 1320 // BrowserView, private: | 1262 // BrowserView, private: |
| 1321 | 1263 |
| 1322 void BrowserView::InitSystemMenu() { | 1264 void BrowserView::InitSystemMenu() { |
| 1323 HMENU system_menu = GetSystemMenu(frame_->GetHWND(), FALSE); | 1265 HMENU system_menu = GetSystemMenu(frame_->GetHWND(), FALSE); |
| 1324 system_menu_.reset(new Menu(system_menu)); | 1266 system_menu_.reset(new Menu(system_menu)); |
| 1325 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); | 1267 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); |
| 1326 // We add the menu items in reverse order so that insertion_index never needs | 1268 // We add the menu items in reverse order so that insertion_index never needs |
| 1327 // to change. | 1269 // to change. |
| 1328 if (IsBrowserTypeNormal()) { | 1270 if (IsBrowserTypeNormal()) { |
| 1329 system_menu_->AddSeparator(insertion_index); | 1271 system_menu_->AddSeparator(insertion_index); |
| 1330 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASK_MANAGER, | 1272 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASK_MANAGER, |
| 1331 l10n_util::GetString(IDS_TASK_MANAGER)); | 1273 l10n_util::GetString(IDS_TASK_MANAGER)); |
| 1332 // If it's a regular browser window with tabs, we don't add any more items, | 1274 // If it's a regular browser window with tabs, we don't add any more items, |
| 1333 // since it already has menus (Page, Chrome). | 1275 // since it already has menus (Page, Chrome). |
| 1334 } else { | 1276 } else { |
| 1335 BuildMenuForTabStriplessWindow(system_menu_.get(), insertion_index); | 1277 BuildMenuForTabStriplessWindow(system_menu_.get(), insertion_index); |
| 1336 } | 1278 } |
| 1337 } | 1279 } |
| 1338 | 1280 |
| 1339 bool BrowserView::ShouldForwardToTabStrip( | |
| 1340 const views::DropTargetEvent& event) { | |
| 1341 if (!tabstrip_->IsVisible()) | |
| 1342 return false; | |
| 1343 | |
| 1344 const int tab_y = tabstrip_->y(); | |
| 1345 const int tab_height = tabstrip_->height(); | |
| 1346 if (event.y() >= tab_y + tab_height) | |
| 1347 return false; | |
| 1348 | |
| 1349 if (event.y() >= tab_y) | |
| 1350 return true; | |
| 1351 | |
| 1352 // Mouse isn't over the tab strip. Only forward if the mouse isn't over | |
| 1353 // another view on the tab strip or is over a view we were told the user can | |
| 1354 // drop on. | |
| 1355 views::View* view_over_mouse = GetViewForPoint(event.location()); | |
| 1356 return (view_over_mouse == this || view_over_mouse == tabstrip_ || | |
| 1357 dropable_views_.find(view_over_mouse) != dropable_views_.end()); | |
| 1358 } | |
| 1359 | |
| 1360 views::DropTargetEvent* BrowserView::MapEventToTabStrip( | |
| 1361 const views::DropTargetEvent& event) { | |
| 1362 gfx::Point tab_strip_loc(event.location()); | |
| 1363 ConvertPointToView(this, tabstrip_, &tab_strip_loc); | |
| 1364 return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(), | |
| 1365 tab_strip_loc.y(), | |
| 1366 event.GetSourceOperations()); | |
| 1367 } | |
| 1368 | |
| 1369 int BrowserView::LayoutTabStrip() { | 1281 int BrowserView::LayoutTabStrip() { |
| 1370 gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); | 1282 gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); |
| 1371 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); | 1283 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); |
| 1372 ConvertPointToView(GetParent(), this, &tabstrip_origin); | 1284 ConvertPointToView(GetParent(), this, &tabstrip_origin); |
| 1373 tabstrip_bounds.set_origin(tabstrip_origin); | 1285 tabstrip_bounds.set_origin(tabstrip_origin); |
| 1374 bool visible = IsTabStripVisible(); | 1286 bool visible = IsTabStripVisible(); |
| 1375 int y = visible ? tabstrip_bounds.y() : 0; | 1287 int y = visible ? tabstrip_bounds.y() : 0; |
| 1376 int height = visible ? tabstrip_bounds.height() : 0; | 1288 int height = visible ? tabstrip_bounds.height() : 0; |
| 1377 tabstrip_->SetVisible(visible); | 1289 tabstrip_->SetVisible(visible); |
| 1378 tabstrip_->SetBounds(tabstrip_bounds.x(), y, tabstrip_bounds.width(), height); | 1290 tabstrip_->SetBounds(tabstrip_bounds.x(), y, tabstrip_bounds.width(), height); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 } | 1616 } |
| 1705 } | 1617 } |
| 1706 | 1618 |
| 1707 // static | 1619 // static |
| 1708 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 1620 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
| 1709 BrowserView* browser_view = new BrowserView(browser); | 1621 BrowserView* browser_view = new BrowserView(browser); |
| 1710 (new BrowserFrame(browser_view))->Init(); | 1622 (new BrowserFrame(browser_view))->Init(); |
| 1711 return browser_view; | 1623 return browser_view; |
| 1712 } | 1624 } |
| 1713 | 1625 |
| OLD | NEW |