Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * | 5 * |
| 6 * Use of this source code is governed by a BSD-style license that can be | 6 * Use of this source code is governed by a BSD-style license that can be |
| 7 * found in the LICENSE file. | 7 * found in the LICENSE file. |
| 8 * | 8 * |
| 9 */ | 9 */ |
| 10 #include <v8.h> | 10 #include <v8.h> |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color), | 151 sprintf(buf, "#%02X%02X%02X", SkColorGetR(color), SkColorGetG(color), |
| 152 SkColorGetB(color)); | 152 SkColorGetB(color)); |
| 153 | 153 |
| 154 info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf)); | 154 info.GetReturnValue().Set(String::NewFromUtf8(info.GetIsolate(), buf)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void JsContext::SetStyle(Local<String> name, Local<Value> value, | 157 void JsContext::SetStyle(Local<String> name, Local<Value> value, |
| 158 const PropertyCallbackInfo<void>& info, | 158 const PropertyCallbackInfo<void>& info, |
| 159 SkPaint& style) { | 159 SkPaint& style) { |
| 160 Local<String> s = value->ToString(); | 160 Local<String> s = value->ToString(); |
| 161 if (s->Length() != 7) { | 161 if (s->Length() != 7 && s->Length() != 9) { |
| 162 info.GetIsolate()->ThrowException( | 162 info.GetIsolate()->ThrowException( |
| 163 v8::String::NewFromUtf8( | 163 v8::String::NewFromUtf8( |
|
robertphillips
2014/01/13 17:49:56
length?
jcgregorio
2014/01/13 17:52:41
Done.
| |
| 164 info.GetIsolate(), "Invalid fill style format.")); | 164 info.GetIsolate(), "Invalid fill style format lenth.")); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 char buf[8]; | 167 char buf[10]; |
| 168 s->WriteUtf8(buf, sizeof(buf)); | 168 s->WriteUtf8(buf, sizeof(buf)); |
| 169 | 169 |
| 170 if (buf[0] != '#') { | 170 if (buf[0] != '#') { |
| 171 info.GetIsolate()->ThrowException( | 171 info.GetIsolate()->ThrowException( |
| 172 v8::String::NewFromUtf8( | 172 v8::String::NewFromUtf8( |
| 173 info.GetIsolate(), "Invalid fill style format.")); | 173 info.GetIsolate(), "Invalid fill style format.")); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Colors can be RRGGBBAA, but SkColor uses ARGB. | |
| 177 long color = strtol(buf+1, NULL, 16); | 178 long color = strtol(buf+1, NULL, 16); |
| 178 style.setColor(SkColorSetA(SkColor(color), SK_AlphaOPAQUE)); | 179 uint32_t alpha = SK_AlphaOPAQUE; |
| 180 if (s->Length() == 9) { | |
| 181 alpha = color & 0xFF; | |
| 182 color >>= 8; | |
| 183 } | |
| 184 style.setColor(SkColorSetA(SkColor(color), alpha)); | |
| 179 } | 185 } |
| 180 | 186 |
| 181 void JsContext::GetFillStyle(Local<String> name, | 187 void JsContext::GetFillStyle(Local<String> name, |
| 182 const PropertyCallbackInfo<Value>& info) { | 188 const PropertyCallbackInfo<Value>& info) { |
| 183 JsContext* jsContext = Unwrap(info.This()); | 189 JsContext* jsContext = Unwrap(info.This()); |
| 184 GetStyle(name, info, jsContext->fFillStyle); | 190 GetStyle(name, info, jsContext->fFillStyle); |
| 185 } | 191 } |
| 186 | 192 |
| 187 void JsContext::GetStrokeStyle(Local<String> name, | 193 void JsContext::GetStrokeStyle(Local<String> name, |
| 188 const PropertyCallbackInfo<Value>& info) { | 194 const PropertyCallbackInfo<Value>& info) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 | 373 |
| 368 // It is a function; cast it to a Function. | 374 // It is a function; cast it to a Function. |
| 369 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val); | 375 Handle<Function> fn_fun = Handle<Function>::Cast(fn_val); |
| 370 | 376 |
| 371 // Store the function in a Persistent handle, since we also want that to | 377 // Store the function in a Persistent handle, since we also want that to |
| 372 // remain after this call returns. | 378 // remain after this call returns. |
| 373 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun); | 379 fOnDraw.Reset(fGlobal->getIsolate(), fn_fun); |
| 374 | 380 |
| 375 return true; | 381 return true; |
| 376 } | 382 } |
| OLD | NEW |