: SuggestionSpan.FLAG_GRAMMAR_ERROR),Chuong Ho-Dacshould this be flipped around, so the default (incl. for when there's a 3rd SpellingMarker.Decoration added, but this code isn't updated) remains FLAG_MISSPELLED, which looks more reasonable to be the default? Lines 184-185 also use SPELLING as default.
Thanks, that soudns good
Math.min(marker.end(), text.length() - 1),Chuong Ho-DacIn follow-up: I will let you double check. Previously the `gfx::Range` documented that `end` was exclusive. So there is an off-by-one error here.
If your SpellingMarker is using an inclusive range, then this is correct.
Great thanks for spotting that. It should be inclusive-exclusive.
mStart = Math.min(start, end);Chuong Ho-Dacnit: also clamp to non-negative?
I've added the assert's.
if (marker.start >= text_length || marker.end >= text_length) {Chuong Ho-DacIn follow-up: I will let you double check. Previously the `gfx::Range` documented that `end` was exclusive. So there is an off-by-one error here.
If your SpellingMarker is using an inclusive range, then this is correct.
fixed. Thanks!
const std::vector<spellcheck::SpellingMarker> spelling_markers_;Chuong Ho-Dacnit: why const now? maybe done separately if really needed.
it should be `const` because the spelling request is meant to have spelling markers fixed but I agree it should be a different CL.
struct SpellingMarker {Chuong Ho-DacCould you add a description. In particular, I would be interested to know if `end` is inclusive or exclusive.
Note that the `gfx::Range` description was:
```
// This class represents either a forward range [min, max) or a reverse range
// (max, min]. |start_| is always the first of these and |end_| the second; as a
// result, the range is forward if (start_ <= end_). The zero-width range
// [val, val) is legal, contains and intersects itself, and is contained by and
// intersects any nonempty range [min, max) where min <= val < max.
```
End should be exclusive. So it should be [start, end)
output->start = std::min(input.start(), input.end());Chuong Ho-Dacnit: also clamp to non-negative?
probably no need, since the SpellingMarker in mojom, we define the start and end to be non-negative already?
```
struct SpellingMarker {
uint32 start;
uint32 end;
Decoration marker_type;
};
```
output->start = std::min(input.start(), input.end());
output->end = std::max(input.start(), input.end());Chuong Ho-DacNote that gfx::Range could have end < start. I will let you double check what makes sense in your case.
----
If we disallow negative range, maybe this should be written:
```
if (input.start() > input.end()) {
return false;
}output->start = input.start();
output->end = input.end();
```
?This would avoid potential error to go unnoticed.
Unlike a normal selection that has direction (users can select from beginning -> end of a word or from the end of the word to the beginning), the spelling markers are just a underline and should be non-directional.
Spelling marker underlines are constructed from `offset` and `offset + length`, therefore `start` must be <= `end`. The range should also be [inclusive, exclusive)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Patchset 22 (latest) looks similar to my last-reviewed Patchset 19, except for copyright year 2025 -> 2026. Rebase or upload hiccoughs?
| Code-Review | +1 |
LGTM with nits:
struct SpellingMarker {Could you please:
// This class represents spelling markers, i.e. Spelling, Grammar.
struct SpellingMarker {
SpellingMarker(uint32_t start, uint32_t end, Decoration marker_type);
SpellingMarker();
SpellingMarker(const SpellingMarker&);
SpellingMarker& operator=(const SpellingMarker&);
~SpellingMarker();
bool operator==(const SpellingMarker& other) const;
uint32_t start;
uint32_t end;
Decoration marker_type;
};IMO, this is a POD.
I would just define it as:
```
struct SpellingMarker {
auto operator<=>(const SpellingMarker& other) const = default;
uint32_t start;
uint32_t end;
Decoration marker_type;
}
```
Then you get nice default, and you don't need to define any function?
bool operator==(const SpellingMarker& other) const;What about a defaulted `<` `<=` `==` `=>` `>` operators?
```
auto operator<=>(const SpellingMarker& other) const = default.
```
default:
NOTREACHED();
}ditto
```suggestion
}
NOTREACHED();
```
WebTextCheckClient::SpellingMarkerType MapToWebSpellingMarkerType(
DocumentMarker::MarkerType marker_type) {
switch (marker_type) {
case DocumentMarker::MarkerType::kSpelling:
return WebTextCheckClient::SpellingMarkerType::kSpelling;
case DocumentMarker::MarkerType::kGrammar:
return WebTextCheckClient::SpellingMarkerType::kGrammar;
default:
NOTREACHED();
}
}
Prefer switch statement to be exhaustive. This will make the compiler to emit an error when new values are added, but we don't yet support it.
```suggestion
WebTextCheckClient::SpellingMarkerType MapToWebSpellingMarkerType(
DocumentMarker::MarkerType marker_type) {
switch (marker_type) {
case DocumentMarker::MarkerType::kSpelling:
return WebTextCheckClient::SpellingMarkerType::kSpelling;
case DocumentMarker::MarkerType::kGrammar:
return WebTextCheckClient::SpellingMarkerType::kGrammar;
}
NOTREACHED();
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Patchset 22 (latest) looks similar to my last-reviewed Patchset 19, except for copyright year 2025 -> 2026. Rebase or upload hiccoughs?
Done, I forgot to upload.
Could you please:
- Add class level comment.
- Document invariants: start<=end?
Done
// This class represents spelling markers, i.e. Spelling, Grammar.
struct SpellingMarker {
SpellingMarker(uint32_t start, uint32_t end, Decoration marker_type);
SpellingMarker();
SpellingMarker(const SpellingMarker&);
SpellingMarker& operator=(const SpellingMarker&);
~SpellingMarker();
bool operator==(const SpellingMarker& other) const;
uint32_t start;
uint32_t end;
Decoration marker_type;
};IMO, this is a POD.
I would just define it as:
```
struct SpellingMarker {
auto operator<=>(const SpellingMarker& other) const = default;uint32_t start;
uint32_t end;
Decoration marker_type;
}
```Then you get nice default, and you don't need to define any function?
Done
What about a defaulted `<` `<=` `==` `=>` `>` operators?
```
auto operator<=>(const SpellingMarker& other) const = default.
```
Done
default:
NOTREACHED();
}Chuong Ho-Dacditto
```suggestion
}
NOTREACHED();
```
Done
WebTextCheckClient::SpellingMarkerType MapToWebSpellingMarkerType(
DocumentMarker::MarkerType marker_type) {
switch (marker_type) {
case DocumentMarker::MarkerType::kSpelling:
return WebTextCheckClient::SpellingMarkerType::kSpelling;
case DocumentMarker::MarkerType::kGrammar:
return WebTextCheckClient::SpellingMarkerType::kGrammar;
default:
NOTREACHED();
}
}
Prefer switch statement to be exhaustive. This will make the compiler to emit an error when new values are added, but we don't yet support it.
```suggestion
WebTextCheckClient::SpellingMarkerType MapToWebSpellingMarkerType(
DocumentMarker::MarkerType marker_type) {
switch (marker_type) {
case DocumentMarker::MarkerType::kSpelling:
return WebTextCheckClient::SpellingMarkerType::kSpelling;
case DocumentMarker::MarkerType::kGrammar:
return WebTextCheckClient::SpellingMarkerType::kGrammar;
}
NOTREACHED();
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
marker.type() != SpellingMarker.Decoration.SPELLING"type == GRAMMAR ? GRAMMAR : SPELLING)", else it's effectively still "GRAMMAR is default", while I reckon SPELLING had better be the default.
assert start >= 0;
assert end >= 0;Refs:
auto operator<=>(const SpellingMarker& other) const = default;I don't think autogen default operator< and operator> make sense for a SpellingMarker.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
marker.type() != SpellingMarker.Decoration.SPELLING"type == GRAMMAR ? GRAMMAR : SPELLING)", else it's effectively still "GRAMMAR is default", while I reckon SPELLING had better be the default.
Done
assert start >= 0;
assert end >= 0;
- Should "start <= end" condition be similarly checked?
- I think generally runtime IllegalArgumentException is preferred.
Refs:
- go/java-practices/assertions
- http://go/java-practices/preconditions
Done
auto operator<=>(const SpellingMarker& other) const = default;I don't think autogen default operator< and operator> make sense for a SpellingMarker.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
public boolean equals(Object o) {[nit, Java] Sorry I missed this earlier. Should also implement hashCode(), even though this hasn't participated in hash-related stuff now. Ref: http://go/java-practices/equals
public String toString() {[nit, optional, Java] Sorry I missed this earlier. Optionally consider String.format() with placeholders, instead of "+" concats.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[nit, Java] Sorry I missed this earlier. Should also implement hashCode(), even though this hasn't participated in hash-related stuff now. Ref: http://go/java-practices/equals
Done
[nit, optional, Java] Sorry I missed this earlier. Optionally consider String.format() with placeholders, instead of "+" concats.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
chrome/browser/site_isolation/spellcheck_per_process_browsertest.cc LGTM.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
spellcheck: supply full spelling marker info, incld. marker type
This CL sends the marker type (misspelling vs grammar) of the spelling
marker. Previously only misspelling markers were sent.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |