| 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 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/mac/sdk_forward_declarations.h" | 12 #include "base/mac/sdk_forward_declarations.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #include "chrome/browser/ui/cocoa/l10n_util.h" |
| 17 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 18 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 18 #include "components/bubble/bubble_controller.h" | 19 #include "components/bubble/bubble_controller.h" |
| 19 #include "ui/base/cocoa/cocoa_base_utils.h" | 20 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 20 | 21 |
| 21 @interface BaseBubbleController (Private) | 22 @interface BaseBubbleController (Private) |
| 22 - (void)registerForNotifications; | 23 - (void)registerForNotifications; |
| 23 - (void)updateOriginFromAnchor; | 24 - (void)updateOriginFromAnchor; |
| 24 - (void)activateTabWithContents:(content::WebContents*)newContents | 25 - (void)activateTabWithContents:(content::WebContents*)newContents |
| 25 previousContents:(content::WebContents*)oldContents | 26 previousContents:(content::WebContents*)oldContents |
| 26 atIndex:(NSInteger)index | 27 atIndex:(NSInteger)index |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // This is not a "real" cancel as potential changes to the radio group are not | 397 // This is not a "real" cancel as potential changes to the radio group are not |
| 397 // undone. That's ok. | 398 // undone. That's ok. |
| 398 [self closeBubbleWithReason:BUBBLE_CLOSE_CANCELED]; | 399 [self closeBubbleWithReason:BUBBLE_CLOSE_CANCELED]; |
| 399 } | 400 } |
| 400 | 401 |
| 401 // Takes the |anchor_| point and adjusts the window's origin accordingly. | 402 // Takes the |anchor_| point and adjusts the window's origin accordingly. |
| 402 - (void)updateOriginFromAnchor { | 403 - (void)updateOriginFromAnchor { |
| 403 NSWindow* window = [self window]; | 404 NSWindow* window = [self window]; |
| 404 NSPoint origin = anchor_; | 405 NSPoint origin = anchor_; |
| 405 | 406 |
| 407 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
| 406 switch ([bubble_ alignment]) { | 408 switch ([bubble_ alignment]) { |
| 407 case info_bubble::kAlignArrowToAnchor: { | 409 case info_bubble::kAlignArrowToAnchor: { |
| 408 NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + | 410 NSSize offsets = NSMakeSize(info_bubble::kBubbleArrowXOffset + |
| 409 info_bubble::kBubbleArrowWidth / 2.0, 0); | 411 info_bubble::kBubbleArrowWidth / 2.0, 0); |
| 410 offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; | 412 offsets = [[parentWindow_ contentView] convertSize:offsets toView:nil]; |
| 411 switch ([bubble_ arrowLocation]) { | 413 switch ([bubble_ arrowLocation]) { |
| 412 case info_bubble::kTopRight: | 414 case info_bubble::kTopRight: |
| 413 origin.x -= NSWidth([window frame]) - offsets.width; | 415 origin.x -= NSWidth([window frame]) - offsets.width; |
| 414 break; | 416 break; |
| 415 case info_bubble::kTopLeft: | 417 case info_bubble::kTopLeft: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 427 case info_bubble::kAlignEdgeToAnchorEdge: | 429 case info_bubble::kAlignEdgeToAnchorEdge: |
| 428 // If the arrow is to the right then move the origin so that the right | 430 // If the arrow is to the right then move the origin so that the right |
| 429 // edge aligns with the anchor. If the arrow is to the left then there's | 431 // edge aligns with the anchor. If the arrow is to the left then there's |
| 430 // nothing to do because the left edge is already aligned with the left | 432 // nothing to do because the left edge is already aligned with the left |
| 431 // edge of the anchor. | 433 // edge of the anchor. |
| 432 if ([bubble_ arrowLocation] == info_bubble::kTopRight) { | 434 if ([bubble_ arrowLocation] == info_bubble::kTopRight) { |
| 433 origin.x -= NSWidth([window frame]); | 435 origin.x -= NSWidth([window frame]); |
| 434 } | 436 } |
| 435 break; | 437 break; |
| 436 | 438 |
| 437 case info_bubble::kAlignRightEdgeToAnchorEdge: | 439 case info_bubble::kAlignTrailingEdgeToAnchorEdge: |
| 438 origin.x -= NSWidth([window frame]); | 440 if (!isRTL) |
| 441 origin.x -= NSWidth([window frame]); |
| 439 break; | 442 break; |
| 440 | 443 |
| 441 case info_bubble::kAlignLeftEdgeToAnchorEdge: | 444 case info_bubble::kAlignLeadingEdgeToAnchorEdge: |
| 442 // Nothing to do. | 445 if (isRTL) |
| 446 origin.x -= NSWidth([window frame]); |
| 443 break; | 447 break; |
| 444 | 448 |
| 445 default: | 449 default: |
| 446 NOTREACHED(); | 450 NOTREACHED(); |
| 447 } | 451 } |
| 448 | 452 |
| 449 origin.y -= NSHeight([window frame]); | 453 origin.y -= NSHeight([window frame]); |
| 450 [window setFrameOrigin:origin]; | 454 [window setFrameOrigin:origin]; |
| 451 } | 455 } |
| 452 | 456 |
| 453 - (void)activateTabWithContents:(content::WebContents*)newContents | 457 - (void)activateTabWithContents:(content::WebContents*)newContents |
| 454 previousContents:(content::WebContents*)oldContents | 458 previousContents:(content::WebContents*)oldContents |
| 455 atIndex:(NSInteger)index | 459 atIndex:(NSInteger)index |
| 456 reason:(int)reason { | 460 reason:(int)reason { |
| 457 // The user switched tabs; close. | 461 // The user switched tabs; close. |
| 458 [self closeBubble]; | 462 [self closeBubble]; |
| 459 } | 463 } |
| 460 | 464 |
| 461 @end // BaseBubbleController | 465 @end // BaseBubbleController |
| OLD | NEW |