| 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 frame_(NULL), | 202 frame_(NULL), |
| 203 browser_(browser), | 203 browser_(browser), |
| 204 active_bookmark_bar_(NULL), | 204 active_bookmark_bar_(NULL), |
| 205 active_download_shelf_(NULL), | 205 active_download_shelf_(NULL), |
| 206 toolbar_(NULL), | 206 toolbar_(NULL), |
| 207 infobar_container_(NULL), | 207 infobar_container_(NULL), |
| 208 find_bar_y_(0), | 208 find_bar_y_(0), |
| 209 contents_container_(NULL), | 209 contents_container_(NULL), |
| 210 initialized_(false), | 210 initialized_(false), |
| 211 fullscreen_(false), | 211 fullscreen_(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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 SchedulePaint(); | 1228 SchedulePaint(); |
| 1234 } | 1229 } |
| 1235 | 1230 |
| 1236 void BrowserView::ViewHierarchyChanged(bool is_add, | 1231 void BrowserView::ViewHierarchyChanged(bool is_add, |
| 1237 views::View* parent, | 1232 views::View* parent, |
| 1238 views::View* child) { | 1233 views::View* child) { |
| 1239 if (is_add && child == this && GetWidget() && !initialized_) { | 1234 if (is_add && child == this && GetWidget() && !initialized_) { |
| 1240 Init(); | 1235 Init(); |
| 1241 initialized_ = true; | 1236 initialized_ = true; |
| 1242 } | 1237 } |
| 1243 if (!is_add) | |
| 1244 dropable_views_.erase(child); | |
| 1245 } | 1238 } |
| 1246 | 1239 |
| 1247 bool BrowserView::CanDrop(const OSExchangeData& data) { | |
| 1248 can_drop_ = (tabstrip_->IsVisible() && !tabstrip_->IsAnimating() && | |
| 1249 data.HasURL()); | |
| 1250 return can_drop_; | |
| 1251 } | |
| 1252 | |
| 1253 void BrowserView::OnDragEntered(const views::DropTargetEvent& event) { | |
| 1254 if (can_drop_ && ShouldForwardToTabStrip(event)) { | |
| 1255 forwarding_to_tab_strip_ = true; | |
| 1256 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1257 MapEventToTabStrip(event)); | |
| 1258 tabstrip_->OnDragEntered(*mapped_event.get()); | |
| 1259 } | |
| 1260 } | |
| 1261 | |
| 1262 int BrowserView::OnDragUpdated(const views::DropTargetEvent& event) { | |
| 1263 if (can_drop_) { | |
| 1264 if (ShouldForwardToTabStrip(event)) { | |
| 1265 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1266 MapEventToTabStrip(event)); | |
| 1267 if (!forwarding_to_tab_strip_) { | |
| 1268 tabstrip_->OnDragEntered(*mapped_event.get()); | |
| 1269 forwarding_to_tab_strip_ = true; | |
| 1270 } | |
| 1271 return tabstrip_->OnDragUpdated(*mapped_event.get()); | |
| 1272 } else if (forwarding_to_tab_strip_) { | |
| 1273 forwarding_to_tab_strip_ = false; | |
| 1274 tabstrip_->OnDragExited(); | |
| 1275 } | |
| 1276 } | |
| 1277 return DragDropTypes::DRAG_NONE; | |
| 1278 } | |
| 1279 | |
| 1280 void BrowserView::OnDragExited() { | |
| 1281 if (forwarding_to_tab_strip_) { | |
| 1282 forwarding_to_tab_strip_ = false; | |
| 1283 tabstrip_->OnDragExited(); | |
| 1284 } | |
| 1285 } | |
| 1286 | |
| 1287 int BrowserView::OnPerformDrop(const views::DropTargetEvent& event) { | |
| 1288 if (forwarding_to_tab_strip_) { | |
| 1289 forwarding_to_tab_strip_ = false; | |
| 1290 scoped_ptr<views::DropTargetEvent> mapped_event( | |
| 1291 MapEventToTabStrip(event)); | |
| 1292 return tabstrip_->OnPerformDrop(*mapped_event.get()); | |
| 1293 } | |
| 1294 return DragDropTypes::DRAG_NONE; | |
| 1295 } | |
| 1296 | |
| 1297 | |
| 1298 /////////////////////////////////////////////////////////////////////////////// | 1240 /////////////////////////////////////////////////////////////////////////////// |
| 1299 // BrowserView, private: | 1241 // BrowserView, private: |
| 1300 | 1242 |
| 1301 void BrowserView::InitSystemMenu() { | 1243 void BrowserView::InitSystemMenu() { |
| 1302 HMENU system_menu = GetSystemMenu(frame_->GetHWND(), FALSE); | 1244 HMENU system_menu = GetSystemMenu(frame_->GetHWND(), FALSE); |
| 1303 system_menu_.reset(new Menu(system_menu)); | 1245 system_menu_.reset(new Menu(system_menu)); |
| 1304 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); | 1246 int insertion_index = std::max(0, system_menu_->ItemCount() - 1); |
| 1305 // We add the menu items in reverse order so that insertion_index never needs | 1247 // We add the menu items in reverse order so that insertion_index never needs |
| 1306 // to change. | 1248 // to change. |
| 1307 if (IsBrowserTypeNormal()) { | 1249 if (IsBrowserTypeNormal()) { |
| 1308 system_menu_->AddSeparator(insertion_index); | 1250 system_menu_->AddSeparator(insertion_index); |
| 1309 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASK_MANAGER, | 1251 system_menu_->AddMenuItemWithLabel(insertion_index, IDC_TASK_MANAGER, |
| 1310 l10n_util::GetString(IDS_TASK_MANAGER)); | 1252 l10n_util::GetString(IDS_TASK_MANAGER)); |
| 1311 // If it's a regular browser window with tabs, we don't add any more items, | 1253 // If it's a regular browser window with tabs, we don't add any more items, |
| 1312 // since it already has menus (Page, Chrome). | 1254 // since it already has menus (Page, Chrome). |
| 1313 } else { | 1255 } else { |
| 1314 BuildMenuForTabStriplessWindow(system_menu_.get(), insertion_index); | 1256 BuildMenuForTabStriplessWindow(system_menu_.get(), insertion_index); |
| 1315 } | 1257 } |
| 1316 } | 1258 } |
| 1317 | 1259 |
| 1318 bool BrowserView::ShouldForwardToTabStrip( | |
| 1319 const views::DropTargetEvent& event) { | |
| 1320 if (!tabstrip_->IsVisible()) | |
| 1321 return false; | |
| 1322 | |
| 1323 const int tab_y = tabstrip_->y(); | |
| 1324 const int tab_height = tabstrip_->height(); | |
| 1325 if (event.y() >= tab_y + tab_height) | |
| 1326 return false; | |
| 1327 | |
| 1328 if (event.y() >= tab_y) | |
| 1329 return true; | |
| 1330 | |
| 1331 // Mouse isn't over the tab strip. Only forward if the mouse isn't over | |
| 1332 // another view on the tab strip or is over a view we were told the user can | |
| 1333 // drop on. | |
| 1334 views::View* view_over_mouse = GetViewForPoint(event.location()); | |
| 1335 return (view_over_mouse == this || view_over_mouse == tabstrip_ || | |
| 1336 dropable_views_.find(view_over_mouse) != dropable_views_.end()); | |
| 1337 } | |
| 1338 | |
| 1339 views::DropTargetEvent* BrowserView::MapEventToTabStrip( | |
| 1340 const views::DropTargetEvent& event) { | |
| 1341 gfx::Point tab_strip_loc(event.location()); | |
| 1342 ConvertPointToView(this, tabstrip_, &tab_strip_loc); | |
| 1343 return new views::DropTargetEvent(event.GetData(), tab_strip_loc.x(), | |
| 1344 tab_strip_loc.y(), | |
| 1345 event.GetSourceOperations()); | |
| 1346 } | |
| 1347 | |
| 1348 int BrowserView::LayoutTabStrip() { | 1260 int BrowserView::LayoutTabStrip() { |
| 1349 gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); | 1261 gfx::Rect tabstrip_bounds = frame_->GetBoundsForTabStrip(tabstrip_); |
| 1350 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); | 1262 gfx::Point tabstrip_origin = tabstrip_bounds.origin(); |
| 1351 ConvertPointToView(GetParent(), this, &tabstrip_origin); | 1263 ConvertPointToView(GetParent(), this, &tabstrip_origin); |
| 1352 tabstrip_bounds.set_origin(tabstrip_origin); | 1264 tabstrip_bounds.set_origin(tabstrip_origin); |
| 1353 bool visible = IsTabStripVisible(); | 1265 bool visible = IsTabStripVisible(); |
| 1354 int y = visible ? tabstrip_bounds.y() : 0; | 1266 int y = visible ? tabstrip_bounds.y() : 0; |
| 1355 int height = visible ? tabstrip_bounds.height() : 0; | 1267 int height = visible ? tabstrip_bounds.height() : 0; |
| 1356 tabstrip_->SetVisible(visible); | 1268 tabstrip_->SetVisible(visible); |
| 1357 tabstrip_->SetBounds(tabstrip_bounds.x(), y, tabstrip_bounds.width(), height); | 1269 tabstrip_->SetBounds(tabstrip_bounds.x(), y, tabstrip_bounds.width(), height); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1682 initialized = true; | 1594 initialized = true; |
| 1683 } | 1595 } |
| 1684 } | 1596 } |
| 1685 | 1597 |
| 1686 // static | 1598 // static |
| 1687 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 1599 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
| 1688 BrowserView* browser_view = new BrowserView(browser); | 1600 BrowserView* browser_view = new BrowserView(browser); |
| 1689 (new BrowserFrame(browser_view))->Init(); | 1601 (new BrowserFrame(browser_view))->Init(); |
| 1690 return browser_view; | 1602 return browser_view; |
| 1691 } | 1603 } |
| OLD | NEW |