Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: replace hard coded background color with themed color #2877

Open
wants to merge 7 commits into
base: narwhal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions AppKit/CPColor.j
Expand Up @@ -102,8 +102,10 @@ var cachedBlackColor,
return @{
@"alternate-selected-control-color": [CPNull null],
@"secondary-selected-control-color": [CPNull null],
@"text-background-color": [CPNull null],
@"selected-text-background-color": [CPNull null],
@"selected-text-inactive-background-color": [CPNull null],
@"text-disabled-color": [CPNull null],
@"css-based": NO
};
}
Expand Down Expand Up @@ -506,11 +508,21 @@ var cachedBlackColor,
return [[self _cachedThemeColor] valueForThemeAttribute:@"selected-text-background-color"] || [CPColor colorWithHexString:"99CCFF"];
}

+ (CPColor)textBackgroundColor
{
return [[self _cachedThemeColor] valueForThemeAttribute:@"text-background-color"] || [CPColor colorWithHexString:"FFFFFF"];
}

+ (CPColor)_selectedTextBackgroundColorUnfocussed
{
return [[self _cachedThemeColor] valueForThemeAttribute:@"selected-text-inactive-background-color"] || [CPColor colorWithHexString:"CCCCCC"];
}

+ (CPColor)disabledControlTextColor
{
return [[self _cachedThemeColor] valueForThemeAttribute:@"text-disabled-color"] || [CPColor colorWithRed:0.66 green:0.66 blue:0.66 alpha:1];
}

/* @ignore */
- (id)_initWithCSSString:(CPString)aString
{
Expand Down
29 changes: 19 additions & 10 deletions AppKit/CPTextView/CPTextView.j
Expand Up @@ -190,11 +190,18 @@ var kDelegateRespondsTo_textShouldBeginEditing
#pragma mark -
#pragma mark Class methods

/* <!> FIXME
just a testing characterSet
all of this depend of the current language.
Need some CPLocale support and maybe even a FSM...
*/
+ (CPString)defaultThemeClass
{
return @"textview";
}

+ (CPDictionary)themeAttributes
{
return @{
@"background-color": [CPColor textBackgroundColor],
@"content-inset": CGSizeMake(2, 0)
};
}

#pragma mark -
#pragma mark Init methods
Expand All @@ -209,7 +216,7 @@ var kDelegateRespondsTo_textShouldBeginEditing
[self setEditable:YES];
[self setSelectable:YES];
[self setRichText:NO];
[self setBackgroundColor:[CPColor whiteColor]];
[self setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];

_usesFontPanel = YES;
_allowsUndo = YES;
Expand Down Expand Up @@ -243,8 +250,10 @@ var kDelegateRespondsTo_textShouldBeginEditing
#endif

_selectionRange = CPMakeRange(0, 0);
_textContainerInset = CGSizeMake(2, 0);
_textContainerOrigin = CGPointMake(_bounds.origin.x, _bounds.origin.y);

// We have to || with CGSizeMakeZero() for theme compilation
_textContainerInset = [self currentValueForThemeAttribute:@"content-inset"] || CGSizeMakeZero();
_textContainerOrigin = CGPointMake(_bounds.origin.x + _textContainerInset.width, _bounds.origin.y + _textContainerInset.height);

_selectionGranularity = CPSelectByCharacter;

Expand Down Expand Up @@ -1129,7 +1138,7 @@ Sets the selection to a range of characters in response to user action.
dragPlaceholder = [[CPTextView alloc] initWithFrame:placeholderFrame];
[dragPlaceholder._textStorage replaceCharactersInRange:CPMakeRange(0, 0) withAttributedString:placeholderString];

[dragPlaceholder setBackgroundColor:[CPColor colorWithRed:1 green:1 blue:1 alpha:0]];
[dragPlaceholder setBackgroundColor:[self currentValueForThemeAttribute:@"background-color"]];
[dragPlaceholder setAlphaValue:0.5];

var stringForPasting = [_textStorage attributedSubstringFromRange:CPMakeRangeCopy(_selectionRange)],
Expand Down Expand Up @@ -2276,7 +2285,7 @@ Sets the selection to a range of characters in response to user action.

_placeholderString = aString;

[self setString:[[CPAttributedString alloc] initWithString:_placeholderString attributes:@{CPForegroundColorAttributeName:[CPColor colorWithRed:0.66 green:0.66 blue:0.66 alpha:1]}]];
[self setString:[[CPAttributedString alloc] initWithString:_placeholderString attributes:@{CPForegroundColorAttributeName:[CPColor disabledControlTextColor]}]];
}

- (void)_continuouslyReverseSetBinding
Expand Down
16 changes: 16 additions & 0 deletions AppKit/Themes/Aristo2/ThemeDescriptors.j
Expand Up @@ -50,6 +50,7 @@
@import <AppKit/CPAlert.j>
@import <AppKit/_CPToolTip.j>
@import <AppKit/CPPopover.j>
@import <AppKit/CPTextView.j>

var themedButtonValues = nil,
themedTextFieldValues = nil,
Expand Down Expand Up @@ -3102,6 +3103,21 @@ var themedButtonValues = nil,
return popoverWindowView;
}

+ (CPTextView)themedTextView
{
var textView = [[CPTextView alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 200.0)],

themeValues =
[
[@"background-color", [CPColor whiteColor]],
[@"content-inset", CGSizeMake(2, 0)]
];

[self registerThemeValues:themeValues forView:textView];

return textView;
}

@end


Expand Down