Bug 1090008 Dispatch SelectionStateChanged event for blur, r=roc r=smaug

This commit is contained in:
peter chang 2014-11-27 18:56:00 +01:00
parent 61b6f51e1b
commit b81e773ad6
5 changed files with 27 additions and 16 deletions

View File

@ -1612,7 +1612,7 @@ nsFocusManager::Blur(nsPIDOMWindow* aWindowToClear,
nsRefPtr<SelectionCarets> selectionCarets = presShell->GetSelectionCarets();
if (selectionCarets) {
selectionCarets->SetVisibility(false);
selectionCarets->NotifyBlur();
}
bool clearFirstBlurEvent = false;

View File

@ -595,9 +595,6 @@ BrowserElementChild.prototype = {
_selectionStateChangedHandler: function(e) {
e.stopPropagation();
let boundingClientRect = e.boundingClientRect;
if (!boundingClientRect) {
return;
}
let isCollapsed = (e.selectedText.length == 0);
let isMouseUp = (e.states.indexOf('mouseup') == 0);
@ -644,12 +641,12 @@ BrowserElementChild.prototype = {
let detail = {
rect: {
width: boundingClientRect.width,
height: boundingClientRect.height,
top: boundingClientRect.top,
bottom: boundingClientRect.bottom,
left: boundingClientRect.left,
right: boundingClientRect.right,
width: boundingClientRect ? boundingClientRect.width : 0,
height: boundingClientRect ? boundingClientRect.height : 0,
top: boundingClientRect ? boundingClientRect.top : 0,
bottom: boundingClientRect ? boundingClientRect.bottom : 0,
left: boundingClientRect ? boundingClientRect.left : 0,
right: boundingClientRect ? boundingClientRect.right : 0,
},
commands: {
canSelectAll: this._isCommandEnabled("selectall"),

View File

@ -11,7 +11,8 @@ enum SelectionState {
"keypress",
"selectall",
"collapsetostart",
"collapsetoend"
"collapsetoend",
"blur"
};
dictionary SelectionStateChangedEventInit : EventInit {

View File

@ -1029,6 +1029,16 @@ DispatchSelectionStateChangedEvent(nsIPresShell* aPresShell,
doc->DispatchEvent(event, &ret);
}
void
SelectionCarets::NotifyBlur()
{
SetVisibility(false);
dom::Sequence<SelectionState> state;
state.AppendElement(dom::SelectionState::Blur);
DispatchSelectionStateChangedEvent(mPresShell, nullptr, state);
}
nsresult
SelectionCarets::NotifySelectionChanged(nsIDOMDocument* aDoc,
nsISelection* aSel,

View File

@ -75,6 +75,9 @@ public:
NS_DECL_NSIREFLOWOBSERVER
NS_DECL_NSISELECTIONLISTENER
// Notify selection carets about the blur event to hidden itself
void NotifyBlur();
// nsIScrollObserver
virtual void ScrollPositionChanged() MOZ_OVERRIDE;
@ -87,11 +90,6 @@ public:
nsEventStatus HandleEvent(WidgetEvent* aEvent);
/**
* Set visibility for selection caret.
*/
void SetVisibility(bool aVisible);
bool GetVisibility() const
{
return mVisible;
@ -111,6 +109,11 @@ private:
SelectionCarets() MOZ_DELETE;
/**
* Set visibility for selection caret.
*/
void SetVisibility(bool aVisible);
/**
* Update selection caret position base on current selection range.
*/