Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } | 452 } |
| 453 | 453 |
| 454 void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) { | 454 void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) { |
| 455 if (!popup_) | 455 if (!popup_) |
| 456 return; | 456 return; |
| 457 | 457 |
| 458 // Forward the focus to the renderer. | 458 // Forward the focus to the renderer. |
| 459 popup_->host()->render_view_host()->view()->Focus(); | 459 popup_->host()->render_view_host()->view()->Focus(); |
| 460 } | 460 } |
| 461 | 461 |
| 462 void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble) { | 462 void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble, |
| 463 gfx::NativeView focused_view) { | |
| 463 if (!popup_) | 464 if (!popup_) |
| 464 return; | 465 return; |
| 465 | 466 |
| 467 #if defined(OS_WIN) | |
| 468 // Don't hide when we are loosing focus to a child window. This is the case | |
| 469 // with select popups. | |
| 470 // TODO(jcampan): http://crbugs.com/29131 make that work on toolkit views | |
|
Erik does not do reviews
2009/12/02 01:26:11
typo: crbug.com
| |
| 471 // so this #if defined can be removed. | |
| 472 gfx::NativeView popup_native_view = popup_->native_view(); | |
| 473 gfx::NativeView parent = focused_view; | |
| 474 while (parent = ::GetParent(parent)) { | |
| 475 if (parent == popup_native_view) | |
| 476 return; | |
| 477 } | |
| 478 #endif | |
| 479 | |
| 466 // This is a bit annoying. If you click on the button that generated the | 480 // This is a bit annoying. If you click on the button that generated the |
| 467 // current popup, then we first get this lost focus message, and then | 481 // current popup, then we first get this lost focus message, and then |
| 468 // we get the click action. This results in the popup being immediately | 482 // we get the click action. This results in the popup being immediately |
| 469 // shown again. To workaround this, we put in a delay. | 483 // shown again. To workaround this, we put in a delay. |
| 470 MessageLoop::current()->PostTask(FROM_HERE, | 484 MessageLoop::current()->PostTask(FROM_HERE, |
| 471 task_factory_.NewRunnableMethod(&BrowserActionsContainer::HidePopup)); | 485 task_factory_.NewRunnableMethod(&BrowserActionsContainer::HidePopup)); |
| 472 } | 486 } |
| 473 | 487 |
| 474 int BrowserActionsContainer::GetClippedPreferredWidth(int available_width) { | 488 int BrowserActionsContainer::GetClippedPreferredWidth(int available_width) { |
| 475 if (browser_action_views_.size() == 0) | 489 if (browser_action_views_.size() == 0) |
| 476 return 0; | 490 return 0; |
| 477 | 491 |
| 478 // We have at least one browser action. Make some of them sticky. | 492 // We have at least one browser action. Make some of them sticky. |
| 479 int min_width = kHorizontalPadding * 2 + | 493 int min_width = kHorizontalPadding * 2 + |
| 480 std::min(static_cast<int>(browser_action_views_.size()), | 494 std::min(static_cast<int>(browser_action_views_.size()), |
| 481 kMinimumNumberOfVisibleBrowserActions) * kButtonSize; | 495 kMinimumNumberOfVisibleBrowserActions) * kButtonSize; |
| 482 | 496 |
| 483 // Even if available_width is <= 0, we still return at least the |min_width|. | 497 // Even if available_width is <= 0, we still return at least the |min_width|. |
| 484 if (available_width <= 0) | 498 if (available_width <= 0) |
| 485 return min_width; | 499 return min_width; |
| 486 | 500 |
| 487 return std::max(min_width, available_width - available_width % kButtonSize + | 501 return std::max(min_width, available_width - available_width % kButtonSize + |
| 488 kHorizontalPadding * 2); | 502 kHorizontalPadding * 2); |
| 489 } | 503 } |
| OLD | NEW |