| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "core/dom/Element.h" | 39 #include "core/dom/Element.h" |
| 40 #include "core/dom/Node.h" | 40 #include "core/dom/Node.h" |
| 41 #include "core/dom/Range.h" | 41 #include "core/dom/Range.h" |
| 42 #include "core/editing/FrameSelection.h" | 42 #include "core/editing/FrameSelection.h" |
| 43 #include "core/editing/PlainTextRange.h" | 43 #include "core/editing/PlainTextRange.h" |
| 44 #include "core/editing/iterators/TextIterator.h" | 44 #include "core/editing/iterators/TextIterator.h" |
| 45 #include "core/frame/FrameView.h" | 45 #include "core/frame/FrameView.h" |
| 46 #include "core/frame/LocalFrame.h" | 46 #include "core/frame/LocalFrame.h" |
| 47 #include "core/html/HTMLElement.h" | 47 #include "core/html/HTMLElement.h" |
| 48 #include "core/layout/HitTestResult.h" | 48 #include "core/layout/HitTestResult.h" |
| 49 #include "core/rendering/RenderObject.h" | 49 #include "core/layout/LayoutObject.h" |
| 50 #include "core/rendering/style/RenderStyle.h" | 50 #include "core/rendering/style/RenderStyle.h" |
| 51 #include "platform/fonts/Font.h" | 51 #include "platform/fonts/Font.h" |
| 52 #include "platform/mac/ColorMac.h" | 52 #include "platform/mac/ColorMac.h" |
| 53 #include "public/platform/WebRect.h" | 53 #include "public/platform/WebRect.h" |
| 54 #include "public/web/WebHitTestResult.h" | 54 #include "public/web/WebHitTestResult.h" |
| 55 #include "public/web/WebRange.h" | 55 #include "public/web/WebRange.h" |
| 56 #include "public/web/WebView.h" | 56 #include "public/web/WebView.h" |
| 57 #include "web/WebLocalFrameImpl.h" | 57 #include "web/WebLocalFrameImpl.h" |
| 58 #include "web/WebViewImpl.h" | 58 #include "web/WebViewImpl.h" |
| 59 | 59 |
| 60 using namespace blink; | 60 using namespace blink; |
| 61 | 61 |
| 62 static NSAttributedString* attributedSubstringFromRange(const Range* range) | 62 static NSAttributedString* attributedSubstringFromRange(const Range* range) |
| 63 { | 63 { |
| 64 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]
; | 64 NSMutableAttributedString* string = [[NSMutableAttributedString alloc] init]
; |
| 65 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; | 65 NSMutableDictionary* attrs = [NSMutableDictionary dictionary]; |
| 66 size_t length = range->endOffset() - range->startOffset(); | 66 size_t length = range->endOffset() - range->startOffset(); |
| 67 | 67 |
| 68 unsigned position = 0; | 68 unsigned position = 0; |
| 69 for (TextIterator it(range); !it.atEnd() && [string length] < length; it.adv
ance()) { | 69 for (TextIterator it(range); !it.atEnd() && [string length] < length; it.adv
ance()) { |
| 70 unsigned numCharacters = it.length(); | 70 unsigned numCharacters = it.length(); |
| 71 if (!numCharacters) | 71 if (!numCharacters) |
| 72 continue; | 72 continue; |
| 73 | 73 |
| 74 Node* container = it.startContainer(); | 74 Node* container = it.startContainer(); |
| 75 RenderObject* renderer = container->renderer(); | 75 LayoutObject* renderer = container->renderer(); |
| 76 ASSERT(renderer); | 76 ASSERT(renderer); |
| 77 if (!renderer) | 77 if (!renderer) |
| 78 continue; | 78 continue; |
| 79 | 79 |
| 80 RenderStyle* style = renderer->style(); | 80 RenderStyle* style = renderer->style(); |
| 81 NSFont* font = style->font().primaryFont()->getNSFont(); | 81 NSFont* font = style->font().primaryFont()->getNSFont(); |
| 82 // If the platform font can't be loaded, it's likely that the site is | 82 // If the platform font can't be loaded, it's likely that the site is |
| 83 // using a web font. For now, just use the default font instead. | 83 // using a web font. For now, just use the default font instead. |
| 84 // TODO(rsesek): Change the font activation flags to allow other process
es | 84 // TODO(rsesek): Change the font activation flags to allow other process
es |
| 85 // to use the font. | 85 // to use the font. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (!editable) | 158 if (!editable) |
| 159 return nil; | 159 return nil; |
| 160 RefPtrWillBeRawPtr<Range> range(PlainTextRange(location, location + length).
createRange(*editable)); | 160 RefPtrWillBeRawPtr<Range> range(PlainTextRange(location, location + length).
createRange(*editable)); |
| 161 if (!range) | 161 if (!range) |
| 162 return nil; | 162 return nil; |
| 163 | 163 |
| 164 return attributedSubstringFromRange(range.get()); | 164 return attributedSubstringFromRange(range.get()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |