OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/views/tab_contents/tab_contents_view_views.h" | 5 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "chrome/browser/ui/constrained_window.h" | 10 #include "chrome/browser/ui/constrained_window.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 void TabContentsViewViews::ShowContextMenu(const ContextMenuParams& params) { | 334 void TabContentsViewViews::ShowContextMenu(const ContextMenuParams& params) { |
335 // Allow delegates to handle the context menu operation first. | 335 // Allow delegates to handle the context menu operation first. |
336 if (tab_contents_->delegate() && | 336 if (tab_contents_->delegate() && |
337 tab_contents_->delegate()->HandleContextMenu(params)) { | 337 tab_contents_->delegate()->HandleContextMenu(params)) { |
338 return; | 338 return; |
339 } | 339 } |
340 | 340 |
341 context_menu_.reset(new RenderViewContextMenuViews(tab_contents_, params)); | 341 context_menu_.reset(new RenderViewContextMenuViews(tab_contents_, params)); |
342 context_menu_->Init(); | 342 context_menu_->Init(); |
343 | 343 |
| 344 // Don't show empty menus. |
| 345 if (context_menu_->menu_model().GetItemCount() == 0) |
| 346 return; |
| 347 |
344 gfx::Point screen_point(params.x, params.y); | 348 gfx::Point screen_point(params.x, params.y); |
345 views::View::ConvertPointToScreen(GetRootView(), &screen_point); | 349 views::View::ConvertPointToScreen(GetRootView(), &screen_point); |
346 | 350 |
347 // Enable recursive tasks on the message loop so we can get updates while | 351 // Enable recursive tasks on the message loop so we can get updates while |
348 // the context menu is being displayed. | 352 // the context menu is being displayed. |
349 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 353 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
350 MessageLoop::current()->SetNestableTasksAllowed(true); | 354 MessageLoop::current()->SetNestableTasksAllowed(true); |
351 context_menu_->RunMenuAt(screen_point.x(), screen_point.y()); | 355 context_menu_->RunMenuAt(screen_point.x(), screen_point.y()); |
352 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 356 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
353 } | 357 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 tab_contents_->HideContents(); | 458 tab_contents_->HideContents(); |
455 } | 459 } |
456 } | 460 } |
457 | 461 |
458 void TabContentsViewViews::OnNativeWidgetSizeChanged( | 462 void TabContentsViewViews::OnNativeWidgetSizeChanged( |
459 const gfx::Size& new_size) { | 463 const gfx::Size& new_size) { |
460 if (overlaid_view_) | 464 if (overlaid_view_) |
461 overlaid_view_->SetBounds(gfx::Rect(new_size)); | 465 overlaid_view_->SetBounds(gfx::Rect(new_size)); |
462 views::Widget::OnNativeWidgetSizeChanged(new_size); | 466 views::Widget::OnNativeWidgetSizeChanged(new_size); |
463 } | 467 } |
OLD | NEW |