Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/cocoa/translate_infobar.mm

Issue 2802006: Fix the error found by -Wextra, disable part of the test because it doesn't s... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/translate_infobar.h" 6 #import "chrome/browser/cocoa/translate_infobar.h"
7 7
8 #include "app/l10n_util.h" 8 #include "app/l10n_util.h"
9 #include "base/logging.h" // for NOTREACHED() 9 #include "base/logging.h" // for NOTREACHED()
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "chrome/app/chrome_dll_resource.h" 12 #include "chrome/app/chrome_dll_resource.h"
13 #import "chrome/browser/cocoa/hover_close_button.h" 13 #import "chrome/browser/cocoa/hover_close_button.h"
14 #include "chrome/browser/cocoa/infobar.h" 14 #include "chrome/browser/cocoa/infobar.h"
15 #import "chrome/browser/cocoa/infobar_controller.h" 15 #import "chrome/browser/cocoa/infobar_controller.h"
16 #import "chrome/browser/cocoa/infobar_gradient_view.h" 16 #import "chrome/browser/cocoa/infobar_gradient_view.h"
17 #include "chrome/browser/tab_contents/tab_contents.h" 17 #include "chrome/browser/tab_contents/tab_contents.h"
18 #include "chrome/browser/translate/page_translated_details.h" 18 #include "chrome/browser/translate/page_translated_details.h"
19 #include "chrome/common/notification_service.h" 19 #include "chrome/common/notification_service.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "grit/locale_settings.h" 21 #include "grit/locale_settings.h"
22 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 22 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
23 23
24 // http://crbug.com/46663 disabled since it never worked.
25 #define DISABLE_VERIFY_CONTROL_ORDER 1
26
24 // Colors for translate infobar gradient background. 27 // Colors for translate infobar gradient background.
25 const int kGreyTopColor[] = {0xC0, 0xC0, 0xC0}; 28 const int kGreyTopColor[] = {0xC0, 0xC0, 0xC0};
26 const int kGreyBottomColor[] = {0xCC, 0xCC, 0xCC}; 29 const int kGreyBottomColor[] = {0xCC, 0xCC, 0xCC};
27 30
28 #pragma mark Anonymous helper functions. 31 #pragma mark Anonymous helper functions.
29 namespace { 32 namespace {
30 33
31 // Move the |toMove| view |spacing| pixels before/after the |anchor| view. 34 // Move the |toMove| view |spacing| pixels before/after the |anchor| view.
32 // |after| signifies the side of |anchor| on which to place |toMove|. 35 // |after| signifies the side of |anchor| on which to place |toMove|.
33 void MoveControl(NSView* anchor, NSView* toMove, int spacing, bool after) { 36 void MoveControl(NSView* anchor, NSView* toMove, int spacing, bool after) {
(...skipping 20 matching lines...) Expand all
54 NSRect viewFrame = [toMove frame]; 57 NSRect viewFrame = [toMove frame];
55 58
56 viewFrame.origin.y = 59 viewFrame.origin.y =
57 floor((NSHeight(superViewFrame) - NSHeight(viewFrame))/2.0); 60 floor((NSHeight(superViewFrame) - NSHeight(viewFrame))/2.0);
58 [toMove setFrame:viewFrame]; 61 [toMove setFrame:viewFrame];
59 } 62 }
60 63
61 // Check that the control |before| is ordered visually before the |after| 64 // Check that the control |before| is ordered visually before the |after|
62 // control. 65 // control.
63 // Also, check that there is space between them. 66 // Also, check that there is space between them.
67 // http://crbug.com/46663 the code below seems to be the reverse of this
68 // comment.
69 #if !defined(DISABLE_VERIFY_CONTROL_ORDER)
64 bool VerifyControlOrderAndSpacing(id before, id after) { 70 bool VerifyControlOrderAndSpacing(id before, id after) {
65 NSRect beforeFrame = [before frame]; 71 CGFloat spaceBetweenControls = 0;
66 NSRect afterFrame = [after frame]; 72 if (before && after) {
67 NSUInteger spaceBetweenControls = -1; 73 // When messaging nil, the rects won't always be zeroed (only sizeof(id) is
68 74 // going to be zeroed by the Objective-C runtime, rest will be uninitialized
75 // memory).
76 NSRect beforeFrame = [before frame];
77 NSRect afterFrame = [after frame];
69 spaceBetweenControls = NSMaxX(beforeFrame) - NSMinX(afterFrame); 78 spaceBetweenControls = NSMaxX(beforeFrame) - NSMinX(afterFrame);
70 // RTL case to be used when we have an RTL version of this UI. 79 // RTL case to be used when we have an RTL version of this UI.
71 // spaceBetweenControls = NSMaxX(afterFrame) - NSMinX(beforeFrame); 80 // spaceBetweenControls = NSMaxX(afterFrame) - NSMinX(beforeFrame);
72 81
82 }
83
73 return (spaceBetweenControls >= 0); 84 return (spaceBetweenControls >= 0);
74 } 85 }
86 #endif // !defined(DISABLE_VERIFY_CONTROL_ORDER)
75 87
76 // Creates a label control in the style we need for the translate infobar's 88 // Creates a label control in the style we need for the translate infobar's
77 // labels within |bounds|. 89 // labels within |bounds|.
78 NSTextField* CreateLabel(NSRect bounds) { 90 NSTextField* CreateLabel(NSRect bounds) {
79 NSTextField* ret = [[NSTextField alloc] initWithFrame:bounds]; 91 NSTextField* ret = [[NSTextField alloc] initWithFrame:bounds];
80 [ret setEditable:NO]; 92 [ret setEditable:NO];
81 [ret setDrawsBackground:NO]; 93 [ret setDrawsBackground:NO];
82 [ret setBordered:NO]; 94 [ret setBordered:NO];
83 return ret; 95 return ret;
84 } 96 }
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 LOG(ERROR) << 776 LOG(ERROR) <<
765 "State: " << state << " translationPending " << translationPending << 777 "State: " << state << " translationPending " << translationPending <<
766 " Control @" << i << (hasSuperView ? " has" : " doesn't have") << 778 " Control @" << i << (hasSuperView ? " has" : " doesn't have") <<
767 " a superview" << [[control description] UTF8String] << 779 " a superview" << [[control description] UTF8String] <<
768 " Title=" << [title UTF8String]; 780 " Title=" << [title UTF8String];
769 return false; 781 return false;
770 } 782 }
771 } 783 }
772 784
773 // Step 2: Check that controls are ordered correctly with no overlap. 785 // Step 2: Check that controls are ordered correctly with no overlap.
786 #if !defined(DISABLE_VERIFY_CONTROL_ORDER)
787 // http://crbug.com/46663 this appears to be invalid.
788 // VerifyControlOrderAndSpacing had an unsigned >= 0 bug, so it used to always
789 // return true. With that bug fixed, this loop now can return a failure.
790 // Scanning the code, it's not clear how this would pass since not all
791 // controls are visible and it needs the array order to always match display
792 // order.
774 id previousControl = nil; 793 id previousControl = nil;
775 for (NSUInteger i = 0; i < [allControls count]; ++i) { 794 for (NSUInteger i = 0; i < [allControls count]; ++i) {
776 id control = [allControls objectAtIndex:i]; 795 id control = [allControls objectAtIndex:i];
777 if (!VerifyControlOrderAndSpacing(previousControl, control)) { 796 if (!VerifyControlOrderAndSpacing(previousControl, control)) {
778 LOG(ERROR) << 797 LOG(ERROR) <<
779 "State: " << state << " translationPending " << translationPending << 798 "State: " << state << " translationPending " << translationPending <<
780 " Control @" << i << " not ordered correctly: " << 799 " Control @" << i << " not ordered correctly: " <<
781 [[control description] UTF8String]; 800 [[control description] UTF8String];
782 return false; 801 return false;
783 } 802 }
784 previousControl = control; 803 previousControl = control;
785 } 804 }
805 #endif // !defined(DISABLE_VERIFY_CONTROL_ORDER)
786 806
787 // Step 3: Check other misc. attributes of layout. 807 // Step 3: Check other misc. attributes of layout.
788 if (state == TranslateInfoBarDelegate::kTranslateError && translationPending) 808 if (state == TranslateInfoBarDelegate::kTranslateError && translationPending)
789 { 809 {
790 if ([[label1_ stringValue] length] != 0) { 810 if ([[label1_ stringValue] length] != 0) {
791 LOG(ERROR) << "Expected empty label1_, instead got" << 811 LOG(ERROR) << "Expected empty label1_, instead got" <<
792 [[label1_ description] UTF8String]; 812 [[label1_ description] UTF8String];
793 return false; 813 return false;
794 } 814 }
795 } 815 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 PageTranslatedDetails* page_translated_details = 932 PageTranslatedDetails* page_translated_details =
913 Details<PageTranslatedDetails>(details).ptr(); 933 Details<PageTranslatedDetails>(details).ptr();
914 TranslateErrors::Type error = page_translated_details->error_type; 934 TranslateErrors::Type error = page_translated_details->error_type;
915 TranslateInfoBarDelegate::TranslateState newState = 935 TranslateInfoBarDelegate::TranslateState newState =
916 TranslateInfoBarDelegate::kAfterTranslate; 936 TranslateInfoBarDelegate::kAfterTranslate;
917 if (page_translated_details->error_type != TranslateErrors::NONE) 937 if (page_translated_details->error_type != TranslateErrors::NONE)
918 newState = TranslateInfoBarDelegate::kTranslateError; 938 newState = TranslateInfoBarDelegate::kTranslateError;
919 [controller_ updateState:newState translationPending:false error:error]; 939 [controller_ updateState:newState translationPending:false error:error];
920 940
921 } 941 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698