OLD | NEW |
1 // Copyright (c) 2009 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 9 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
10 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 10 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
11 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 11 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 duration:(float)duration; | 43 duration:(float)duration; |
44 | 44 |
45 // Returns the horizontal position the FindBar should use in order to avoid | 45 // Returns the horizontal position the FindBar should use in order to avoid |
46 // overlapping with the current find result, if there's one. | 46 // overlapping with the current find result, if there's one. |
47 - (float)findBarHorizontalPosition; | 47 - (float)findBarHorizontalPosition; |
48 | 48 |
49 // Adjusts the horizontal position if necessary to avoid overlapping with the | 49 // Adjusts the horizontal position if necessary to avoid overlapping with the |
50 // current find result. | 50 // current find result. |
51 - (void)moveFindBarIfNecessary:(BOOL)animate; | 51 - (void)moveFindBarIfNecessary:(BOOL)animate; |
52 | 52 |
| 53 // Sets the hidden status of the FindBarView and its superview. |
| 54 - (void)setFindBarViewHidden:(BOOL)hidden; |
| 55 |
53 // Optionally stops the current search, puts |text| into the find bar, and | 56 // Optionally stops the current search, puts |text| into the find bar, and |
54 // enables the buttons, but doesn't start a new search for |text|. | 57 // enables the buttons, but doesn't start a new search for |text|. |
55 - (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch; | 58 - (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch; |
56 @end | 59 @end |
57 | 60 |
58 @implementation FindBarCocoaController | 61 @implementation FindBarCocoaController |
59 | 62 |
60 - (id)init { | 63 - (id)init { |
61 if ((self = [super initWithNibName:@"FindBar" | 64 if ((self = [super initWithNibName:@"FindBar" |
62 bundle:base::mac::MainAppBundle()])) { | 65 bundle:base::mac::MainAppBundle()])) { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (animation == showHideAnimation_.get()) { | 374 if (animation == showHideAnimation_.get()) { |
372 [showHideAnimation_.release() autorelease]; | 375 [showHideAnimation_.release() autorelease]; |
373 } else if (animation == moveAnimation_.get()) { | 376 } else if (animation == moveAnimation_.get()) { |
374 [moveAnimation_.release() autorelease]; | 377 [moveAnimation_.release() autorelease]; |
375 } else { | 378 } else { |
376 NOTREACHED(); | 379 NOTREACHED(); |
377 } | 380 } |
378 | 381 |
379 // If the find bar is not visible, make it actually hidden, so it'll no longer | 382 // If the find bar is not visible, make it actually hidden, so it'll no longer |
380 // respond to key events. | 383 // respond to key events. |
381 [findBarView_ setHidden:![self isFindBarVisible]]; | 384 [self setFindBarViewHidden:![self isFindBarVisible]]; |
382 } | 385 } |
383 | 386 |
384 - (gfx::Point)findBarWindowPosition { | 387 - (gfx::Point)findBarWindowPosition { |
385 gfx::Rect view_rect(NSRectToCGRect([[self view] frame])); | 388 gfx::Rect view_rect(NSRectToCGRect([[self view] frame])); |
386 // Convert Cocoa coordinates (Y growing up) to Y growing down. | 389 // Convert Cocoa coordinates (Y growing up) to Y growing down. |
387 // Offset from |maxY_|, which represents the content view's top, instead | 390 // Offset from |maxY_|, which represents the content view's top, instead |
388 // of from the superview, which represents the whole browser window. | 391 // of from the superview, which represents the whole browser window. |
389 view_rect.set_y(maxY_ - view_rect.bottom()); | 392 view_rect.set_y(maxY_ - view_rect.bottom()); |
390 return view_rect.origin(); | 393 return view_rect.origin(); |
391 } | 394 } |
(...skipping 30 matching lines...) Expand all Loading... |
422 animate:(BOOL)animate | 425 animate:(BOOL)animate |
423 duration:(float)duration { | 426 duration:(float)duration { |
424 // Save the current frame. | 427 // Save the current frame. |
425 NSRect startFrame = [findBarView_ frame]; | 428 NSRect startFrame = [findBarView_ frame]; |
426 | 429 |
427 // Stop any existing animations. | 430 // Stop any existing animations. |
428 [showHideAnimation_ stopAnimation]; | 431 [showHideAnimation_ stopAnimation]; |
429 | 432 |
430 if (!animate) { | 433 if (!animate) { |
431 [findBarView_ setFrame:endFrame]; | 434 [findBarView_ setFrame:endFrame]; |
432 [findBarView_ setHidden:![self isFindBarVisible]]; | 435 [self setFindBarViewHidden:![self isFindBarVisible]]; |
433 showHideAnimation_.reset(nil); | 436 showHideAnimation_.reset(nil); |
434 return; | 437 return; |
435 } | 438 } |
436 | 439 |
437 // If animating, ensure that the find bar is not hidden. Hidden status will be | 440 // If animating, ensure that the find bar is not hidden. Hidden status will be |
438 // updated at the end of the animation. | 441 // updated at the end of the animation. |
439 [findBarView_ setHidden:NO]; | 442 [self setFindBarViewHidden:NO]; |
440 | 443 |
441 // Reset the frame to what was saved above. | 444 // Reset the frame to what was saved above. |
442 [findBarView_ setFrame:startFrame]; | 445 [findBarView_ setFrame:startFrame]; |
443 | 446 |
444 showHideAnimation_.reset([self createAnimationForView:findBarView_ | 447 showHideAnimation_.reset([self createAnimationForView:findBarView_ |
445 toFrame:endFrame | 448 toFrame:endFrame |
446 duration:duration]); | 449 duration:duration]); |
447 } | 450 } |
448 | 451 |
449 - (float)findBarHorizontalPosition { | 452 - (float)findBarHorizontalPosition { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 frame.origin.x = x; | 505 frame.origin.x = x; |
503 moveAnimation_.reset([self createAnimationForView:view | 506 moveAnimation_.reset([self createAnimationForView:view |
504 toFrame:frame | 507 toFrame:frame |
505 duration:kFindBarMoveDuration]); | 508 duration:kFindBarMoveDuration]); |
506 } else { | 509 } else { |
507 frame.origin.x = x; | 510 frame.origin.x = x; |
508 [view setFrame:frame]; | 511 [view setFrame:frame]; |
509 } | 512 } |
510 } | 513 } |
511 | 514 |
| 515 - (void)setFindBarViewHidden:(BOOL)hidden { |
| 516 // Set the hidden status of both the findBarView_ and the NSView |
| 517 // of this controller (superview of findBarView_). |
| 518 [findBarView_ setHidden:hidden]; |
| 519 [[self view] setHidden:hidden]; |
| 520 } |
| 521 |
512 - (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch{ | 522 - (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch{ |
513 [self setFindText:text]; | 523 [self setFindText:text]; |
514 | 524 |
515 // End the find session, hide the "x of y" text and disable the | 525 // End the find session, hide the "x of y" text and disable the |
516 // buttons, but do not close the find bar or raise the window here. | 526 // buttons, but do not close the find bar or raise the window here. |
517 if (stopSearch && findBarBridge_) { | 527 if (stopSearch && findBarBridge_) { |
518 TabContentsWrapper* contents = | 528 TabContentsWrapper* contents = |
519 findBarBridge_->GetFindBarController()->tab_contents(); | 529 findBarBridge_->GetFindBarController()->tab_contents(); |
520 if (contents) { | 530 if (contents) { |
521 FindTabHelper* find_tab_helper = contents->find_tab_helper(); | 531 FindTabHelper* find_tab_helper = contents->find_tab_helper(); |
522 find_tab_helper->StopFinding(FindBarController::kClearSelection); | 532 find_tab_helper->StopFinding(FindBarController::kClearSelection); |
523 findBarBridge_->ClearResults(find_tab_helper->find_result()); | 533 findBarBridge_->ClearResults(find_tab_helper->find_result()); |
524 } | 534 } |
525 } | 535 } |
526 | 536 |
527 // Has to happen after |ClearResults()| above. | 537 // Has to happen after |ClearResults()| above. |
528 BOOL buttonsEnabled = [text length] > 0 ? YES : NO; | 538 BOOL buttonsEnabled = [text length] > 0 ? YES : NO; |
529 [previousButton_ setEnabled:buttonsEnabled]; | 539 [previousButton_ setEnabled:buttonsEnabled]; |
530 [nextButton_ setEnabled:buttonsEnabled]; | 540 [nextButton_ setEnabled:buttonsEnabled]; |
531 } | 541 } |
532 | 542 |
533 @end | 543 @end |
OLD | NEW |