void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz) { icaltimetype t = *icalt; mIsValid = (icaltime_is_null_time(t) || icaltime_is_valid_time(t) ? true : false); mIsDate = t.is_date ? true : false; if (mIsDate) { t.hour = 0; t.minute = 0; t.second = 0; } if (mIsValid) { t = icaltime_normalize(t); } mYear = static_cast<int16_t>(t.year); mMonth = static_cast<int16_t>(t.month - 1); mDay = static_cast<int16_t>(t.day); mHour = static_cast<int16_t>(t.hour); mMinute = static_cast<int16_t>(t.minute); mSecond = static_cast<int16_t>(t.second); if (tz) { mTimezone = tz; } else { mTimezone = cal::detectTimezone(t, nullptr); } #if defined(DEBUG) if (mTimezone) { if (t.is_utc) { nsCOMPtr<calITimezone> ctz = cal::UTC(); NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "UTC mismatch!"); } else if (!t.zone) { nsAutoCString tzid; mTimezone->GetTzid(tzid); if (tzid.EqualsLiteral("floating")) { nsCOMPtr<calITimezone> ctz = cal::floating(); NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "floating mismatch!"); } } else { nsAutoCString tzid; mTimezone->GetTzid(tzid); NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))), "tzid mismatch!"); } } #endif mWeekday = static_cast<int16_t>(icaltime_day_of_week(t) - 1); mYearday = static_cast<int16_t>(icaltime_day_of_year(t)); // mNativeTime: not moving the existing date to UTC, // but merely representing it a UTC-based way. t.is_date = 0; mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone()); }
NS_IMETHODIMP nsTypeAheadFind::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) { if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { return PrefsReset(); } else if (!nsCRT::strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) && SameCOMIdentity(aSubject, mCurrentWindow)) { ReleaseStrongMemberVariables(); } return NS_OK; }
void HTMLObjectElement::HandlePluginInstantiated(Element* aElement) { // If aElement is already focused when a plugin is instantiated, we need // to initiate a call to nsIWidget::SetPluginFocused(true). Otherwise // keyboard input won't work in a click-to-play plugin until aElement // loses focus and regains it. nsIContent* focusedContent = nullptr; nsFocusManager *fm = nsFocusManager::GetFocusManager(); if (fm) { focusedContent = fm->GetFocusedContent(); } if (SameCOMIdentity(focusedContent, aElement)) { OnFocusBlurPlugin(aElement, true); } }
NS_IMETHODIMP FetchStream::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { AssertIsOnMainThread(); AssertIsOnOwningThread(); MOZ_ASSERT(strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0); nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal); if (SameCOMIdentity(aSubject, window)) { Close(); } return NS_OK; }
NS_IMETHODIMP HttpServer::OnSocketAccepted(nsIServerSocket* aServ, nsISocketTransport* aTransport) { MOZ_ASSERT(SameCOMIdentity(aServ, mServerSocket)); nsresult rv; RefPtr<Connection> conn = new Connection(aTransport, this, rv); NS_ENSURE_SUCCESS(rv, rv); LOG_I("HttpServer::OnSocketAccepted(%p) - Socket %p", this, conn.get()); mConnections.AppendElement(conn.forget()); return NS_OK; }
NS_IMETHODIMP nsOfflineCachePendingUpdate::OnStateChange(nsIWebProgress* aWebProgress, nsIRequest *aRequest, PRUint32 progressStateFlags, nsresult aStatus) { nsCOMPtr<nsIDOMDocument> updateDoc = do_QueryReferent(mDocument); if (!updateDoc) { // The document that scheduled this update has gone away, // we don't need to listen anymore. aWebProgress->RemoveProgressListener(this); NS_RELEASE_THIS(); return NS_OK; } if (!(progressStateFlags & STATE_STOP)) { return NS_OK; } nsCOMPtr<nsIDOMWindow> window; aWebProgress->GetDOMWindow(getter_AddRefs(window)); if (!window) return NS_OK; nsCOMPtr<nsIDOMDocument> progressDoc; window->GetDocument(getter_AddRefs(progressDoc)); if (!progressDoc) return NS_OK; if (!SameCOMIdentity(progressDoc, updateDoc)) { return NS_OK; } LOG(("nsOfflineCachePendingUpdate::OnStateChange [%p, doc=%p]", this, progressDoc.get())); // Only schedule the update if the document loaded successfully if (NS_SUCCEEDED(aStatus)) { nsCOMPtr<nsIOfflineCacheUpdate> update; mService->Schedule(mManifestURI, mDocumentURI, updateDoc, window, getter_AddRefs(update)); } aWebProgress->RemoveProgressListener(this); NS_RELEASE_THIS(); return NS_OK; }
NS_IMETHODIMP nsHTMLTextAreaElement::Select() { // XXX Bug? We have to give the input focus before contents can be // selected FocusTristate state = FocusState(); if (state == eUnfocusable) { return NS_OK; } nsIFocusManager* fm = nsFocusManager::GetFocusManager(); nsCOMPtr<nsPresContext> presContext = GetPresContext(); if (state == eInactiveWindow) { if (fm) fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL); SelectAll(presContext); return NS_OK; } nsEventStatus status = nsEventStatus_eIgnore; nsGUIEvent event(PR_TRUE, NS_FORM_SELECTED, nsnull); // XXXbz nsHTMLInputElement guards against this reentering; shouldn't we? nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext, &event, nsnull, &status); // If the DOM event was not canceled (e.g. by a JS event handler // returning false) if (status == nsEventStatus_eIgnore) { if (fm) { fm->SetFocus(this, nsIFocusManager::FLAG_NOSCROLL); // ensure that the element is actually focused nsCOMPtr<nsIDOMElement> focusedElement; fm->GetFocusedElement(getter_AddRefs(focusedElement)); if (SameCOMIdentity(static_cast<nsIDOMNode*>(this), focusedElement)) { // Now Select all the text! SelectAll(presContext); } } } return NS_OK; }
NS_IMETHODIMP nsXFormsControlStub::SetAbortedBindListContainer( nsIXFormsContextControl *aControlContainingList) { // A control should never be on more than one aborted bind list. There is // probably a chance through some crazy DOM stirring for a control to be // waiting on notification from a context control and then the control finds // itself trying to bind again under a whole different parent tree. So we'll // have the control remove itself from the old list and link itself to the // new list. if (mAbortedBindListContainer && aControlContainingList) { if (!SameCOMIdentity(mAbortedBindListContainer, aControlContainingList)) { mAbortedBindListContainer->AddRemoveAbortedControl(this, PR_FALSE); } } mAbortedBindListContainer = aControlContainingList; return NS_OK; }
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) override { MOZ_ASSERT(NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0); if (!mStream) { return NS_OK; } nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal); if (!SameCOMIdentity(aSubject, window)) { return NS_OK; } // mStream->Close() will call JSStreamConsumer::OnInputStreamReady which may // then destory itself, dropping the last reference to 'this'. RefPtr<WindowStreamOwner> keepAlive(this); mStream->Close(); mStream = nullptr; mGlobal = nullptr; return NS_OK; }
// Determine if any URI of the window hierarchy of aWindow is foreign with // respect to aSecondURI. See docs for mozIThirdPartyUtil. NS_IMETHODIMP ThirdPartyUtil::IsThirdPartyWindow(nsIDOMWindow* aWindow, nsIURI* aURI, bool* aResult) { NS_ENSURE_ARG(aWindow); NS_ASSERTION(aResult, "null outparam pointer"); bool result; // Get the URI of the window, and its base domain. nsCOMPtr<nsIURI> currentURI = GetURIFromWindow(aWindow); //NS_ENSURE_TRUE(currentURI, NS_ERROR_INVALID_ARG); nsCString bottomDomain; nsresult rv = GetBaseDomain(currentURI, bottomDomain); if (NS_FAILED(rv)) return rv; if (aURI) { // Determine whether aURI is foreign with respect to currentURI. rv = IsThirdPartyInternal(bottomDomain, aURI, &result); if (NS_FAILED(rv)) return rv; if (result) { *aResult = true; return NS_OK; } } nsCOMPtr<nsIDOMWindow> current = aWindow, parent; nsCOMPtr<nsIURI> parentURI; do { // We use GetScriptableParent rather than GetParent because we consider // <iframe mozbrowser/mozapp> to be a top-level frame. rv = current->GetScriptableParent(getter_AddRefs(parent)); NS_ENSURE_SUCCESS(rv, rv); if (SameCOMIdentity(parent, current)) { // We're at the topmost content window. We already know the answer. *aResult = false; return NS_OK; } parentURI = GetURIFromWindow(parent); NS_ENSURE_TRUE(parentURI, NS_ERROR_INVALID_ARG); rv = IsThirdPartyInternal(bottomDomain, parentURI, &result); if (NS_FAILED(rv)) return rv; if (result) { *aResult = true; return NS_OK; } current = parent; currentURI = parentURI; } while (1); NS_NOTREACHED("should've returned"); return NS_ERROR_UNEXPECTED; }
// Determine if the URI associated with aChannel or any URI of the window // hierarchy associated with the channel is foreign with respect to aSecondURI. // See docs for mozIThirdPartyUtil. NS_IMETHODIMP ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel, nsIURI* aURI, bool* aResult) { NS_ENSURE_ARG(aChannel); NS_ASSERTION(aResult, "null outparam pointer"); nsresult rv; bool doForce = false; nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal = do_QueryInterface(aChannel); if (httpChannelInternal) { rv = httpChannelInternal->GetForceAllowThirdPartyCookie(&doForce); NS_ENSURE_SUCCESS(rv, rv); // If aURI was not supplied, and we're forcing, then we're by definition // not foreign. If aURI was supplied, we still want to check whether it's // foreign with respect to the channel URI. (The forcing only applies to // whatever window hierarchy exists above the channel.) if (doForce && !aURI) { *aResult = false; return NS_OK; } } // Obtain the URI from the channel, and its base domain. nsCOMPtr<nsIURI> channelURI; aChannel->GetURI(getter_AddRefs(channelURI)); NS_ENSURE_TRUE(channelURI, NS_ERROR_INVALID_ARG); nsCString channelDomain; rv = GetBaseDomain(channelURI, channelDomain); if (NS_FAILED(rv)) return rv; if (aURI) { // Determine whether aURI is foreign with respect to channelURI. bool result; rv = IsThirdPartyInternal(channelDomain, aURI, &result); if (NS_FAILED(rv)) return rv; // If it's foreign, or we're forcing, we're done. if (result || doForce) { *aResult = result; return NS_OK; } } // Find the associated window and its parent window. nsCOMPtr<nsILoadContext> ctx; NS_QueryNotificationCallbacks(aChannel, ctx); if (!ctx) return NS_ERROR_INVALID_ARG; // If there is no window, the consumer kicking off the load didn't provide one // to the channel. This is limited to loads of certain types of resources. If // those loads require cookies, the forceAllowThirdPartyCookie property should // be set on the channel. nsCOMPtr<nsIDOMWindow> ourWin, parentWin; ctx->GetAssociatedWindow(getter_AddRefs(ourWin)); if (!ourWin) return NS_ERROR_INVALID_ARG; // We use GetScriptableParent rather than GetParent because we consider // <iframe mozbrowser/mozapp> to be a top-level frame. ourWin->GetScriptableParent(getter_AddRefs(parentWin)); NS_ENSURE_TRUE(parentWin, NS_ERROR_INVALID_ARG); // Check whether this is the document channel for this window (representing a // load of a new page). In that situation we want to avoid comparing // channelURI to ourWin, since what's in ourWin right now will be replaced as // the channel loads. This covers the case of a freshly kicked-off load // (e.g. the user typing something in the location bar, or clicking on a // bookmark), where the window's URI hasn't yet been set, and will be bogus. // It also covers situations where a subframe is navigated to someting that // is same-origin with all its ancestors. This is a bit of a nasty hack, but // we will hopefully flag these channels better later. nsLoadFlags flags; rv = aChannel->GetLoadFlags(&flags); NS_ENSURE_SUCCESS(rv, rv); if (flags & nsIChannel::LOAD_DOCUMENT_URI) { if (SameCOMIdentity(ourWin, parentWin)) { // We only need to compare aURI to the channel URI -- the window's will be // bogus. We already know the answer. *aResult = false; return NS_OK; } // Make sure to still compare to ourWin's ancestors ourWin = parentWin; } // Check the window hierarchy. This covers most cases for an ordinary page // load from the location bar. return IsThirdPartyWindow(ourWin, channelURI, aResult); }
NS_IMETHODIMP nsTypeAheadFind::Find(const nsAString& aSearchString, bool aLinksOnly, uint16_t* aResult) { *aResult = FIND_NOTFOUND; nsCOMPtr<nsIPresShell> presShell (GetPresShell()); if (!presShell) { nsCOMPtr<nsIDocShell> ds (do_QueryReferent(mDocShell)); NS_ENSURE_TRUE(ds, NS_ERROR_FAILURE); presShell = ds->GetPresShell(); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); mPresShell = do_GetWeakReference(presShell); } nsCOMPtr<nsISelection> selection; nsCOMPtr<nsISelectionController> selectionController = do_QueryReferent(mSelectionController); if (!selectionController) { GetSelection(presShell, getter_AddRefs(selectionController), getter_AddRefs(selection)); // cache for reuse mSelectionController = do_GetWeakReference(selectionController); } else { selectionController->GetSelection( nsISelectionController::SELECTION_NORMAL, getter_AddRefs(selection)); } if (selection) selection->CollapseToStart(); if (aSearchString.IsEmpty()) { mTypeAheadBuffer.Truncate(); // These will be initialized to their true values after the first character // is typed mStartFindRange = nullptr; mSelectionController = nullptr; *aResult = FIND_FOUND; return NS_OK; } bool atEnd = false; if (mTypeAheadBuffer.Length()) { const nsAString& oldStr = Substring(mTypeAheadBuffer, 0, mTypeAheadBuffer.Length()); const nsAString& newStr = Substring(aSearchString, 0, mTypeAheadBuffer.Length()); if (oldStr.Equals(newStr)) atEnd = true; const nsAString& newStr2 = Substring(aSearchString, 0, aSearchString.Length()); const nsAString& oldStr2 = Substring(mTypeAheadBuffer, 0, aSearchString.Length()); if (oldStr2.Equals(newStr2)) atEnd = true; if (!atEnd) mStartFindRange = nullptr; } if (!mIsSoundInitialized && !mNotFoundSoundURL.IsEmpty()) { // This makes sure system sound library is loaded so that // there's no lag before the first sound is played // by waiting for the first keystroke, we still get the startup time benefits. mIsSoundInitialized = true; mSoundInterface = do_CreateInstance("@mozilla.org/sound;1"); if (mSoundInterface && !mNotFoundSoundURL.EqualsLiteral("beep")) { mSoundInterface->Init(); } } #ifdef XP_WIN // After each keystroke, ensure sound object is destroyed, to free up memory // allocated for error sound, otherwise Windows' nsISound impl // holds onto the last played sound, using up memory. mSoundInterface = nullptr; #endif int32_t bufferLength = mTypeAheadBuffer.Length(); mTypeAheadBuffer = aSearchString; bool isFirstVisiblePreferred = false; // --------- Initialize find if 1st char ---------- if (bufferLength == 0) { // If you can see the selection (not collapsed or thru caret browsing), // or if already focused on a page element, start there. // Otherwise we're going to start at the first visible element bool isSelectionCollapsed = true; if (selection) selection->GetIsCollapsed(&isSelectionCollapsed); // If true, we will scan from top left of visible area // If false, we will scan from start of selection isFirstVisiblePreferred = !atEnd && !mCaretBrowsingOn && isSelectionCollapsed; if (isFirstVisiblePreferred) { // Get the focused content. If there is a focused node, ensure the // selection is at that point. Otherwise, we will just want to start // from the caret position or the beginning of the document. nsPresContext* presContext = presShell->GetPresContext(); NS_ENSURE_TRUE(presContext, NS_OK); nsCOMPtr<nsIDocument> document = do_QueryInterface(presShell->GetDocument()); if (!document) return NS_ERROR_UNEXPECTED; nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(document->GetWindow()); nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID); if (fm) { nsCOMPtr<nsIDOMElement> focusedElement; nsCOMPtr<nsIDOMWindow> focusedWindow; fm->GetFocusedElementForWindow(window, false, getter_AddRefs(focusedWindow), getter_AddRefs(focusedElement)); // If the root element is focused, then it's actually the document // that has the focus, so ignore this. if (focusedElement && !SameCOMIdentity(focusedElement, document->GetRootElement())) { fm->MoveCaretToFocus(window); isFirstVisiblePreferred = false; } } } } // ----------- Find the text! --------------------- // Beware! This may flush notifications via synchronous // ScrollSelectionIntoView. nsresult rv = FindItNow(nullptr, aLinksOnly, isFirstVisiblePreferred, false, aResult); // ---------Handle success or failure --------------- if (NS_SUCCEEDED(rv)) { if (mTypeAheadBuffer.Length() == 1) { // If first letter, store where the first find succeeded // (mStartFindRange) mStartFindRange = nullptr; if (selection) { nsCOMPtr<nsIDOMRange> startFindRange; selection->GetRangeAt(0, getter_AddRefs(startFindRange)); if (startFindRange) startFindRange->CloneRange(getter_AddRefs(mStartFindRange)); } } } else { // Error sound if (mTypeAheadBuffer.Length() > mLastFindLength) PlayNotFoundSound(); } SaveFind(); return NS_OK; }
NS_IMETHODIMP AsyncConnectionHelper::Run() { if (NS_IsMainThread()) { if (mTransaction && mTransaction->IsAborted()) { // Always fire a "error" event with ABORT_ERR if the transaction was // aborted, even if the request succeeded or failed with another error. mResultCode = NS_ERROR_DOM_INDEXEDDB_ABORT_ERR; } IDBTransaction* oldTransaction = gCurrentTransaction; gCurrentTransaction = mTransaction; if (mRequest) { nsresult rv = mRequest->NotifyHelperCompleted(this); if (NS_SUCCEEDED(mResultCode) && NS_FAILED(rv)) { mResultCode = rv; } } // Call OnError if the database had an error or if the OnSuccess handler // has an error. if (NS_FAILED(mResultCode) || NS_FAILED((mResultCode = OnSuccess()))) { OnError(); } NS_ASSERTION(gCurrentTransaction == mTransaction, "Should be unchanged!"); gCurrentTransaction = oldTransaction; if (mDispatched && mTransaction) { mTransaction->OnRequestFinished(); } ReleaseMainThreadObjects(); NS_ASSERTION(!(mDatabase || mTransaction || mRequest), "Subclass didn't " "call AsyncConnectionHelper::ReleaseMainThreadObjects!"); return NS_OK; } nsresult rv = NS_OK; nsCOMPtr<mozIStorageConnection> connection; if (mTransaction) { rv = mTransaction->GetOrCreateConnection(getter_AddRefs(connection)); if (NS_SUCCEEDED(rv)) { NS_ASSERTION(connection, "This should never be null!"); } } bool setProgressHandler = false; if (connection) { rv = connection->SetProgressHandler(kProgressHandlerGranularity, this, getter_AddRefs(mOldProgressHandler)); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "SetProgressHandler failed!"); if (NS_SUCCEEDED(rv)) { setProgressHandler = true; } } if (NS_SUCCEEDED(rv)) { bool hasSavepoint = false; if (mDatabase) { IndexedDatabaseManager::SetCurrentDatabase(mDatabase); // Make the first savepoint. if (mTransaction) { if (!(hasSavepoint = mTransaction->StartSavepoint())) { NS_WARNING("Failed to make savepoint!"); } } } mResultCode = DoDatabaseWork(connection); if (mDatabase) { IndexedDatabaseManager::SetCurrentDatabase(nsnull); // Release or roll back the savepoint depending on the error code. if (hasSavepoint) { NS_ASSERTION(mTransaction, "Huh?!"); if (NS_SUCCEEDED(mResultCode)) { mTransaction->ReleaseSavepoint(); } else { mTransaction->RollbackSavepoint(); } } } } else { // NS_ERROR_NOT_AVAILABLE is our special code for "database is invalidated" // and we should fail with RECOVERABLE_ERR. if (rv == NS_ERROR_NOT_AVAILABLE) { mResultCode = NS_ERROR_DOM_INDEXEDDB_RECOVERABLE_ERR; } else { mResultCode = NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR; } } if (setProgressHandler) { nsCOMPtr<mozIStorageProgressHandler> handler; rv = connection->RemoveProgressHandler(getter_AddRefs(handler)); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "RemoveProgressHandler failed!"); #ifdef DEBUG if (NS_SUCCEEDED(rv)) { NS_ASSERTION(SameCOMIdentity(handler, static_cast<nsIRunnable*>(this)), "Mismatch!"); } #endif } return NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL); }
void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz) { icaltimetype t = *icalt; mIsValid = (icaltime_is_null_time(t) || icaltime_is_valid_time(t) ? PR_TRUE : PR_FALSE); mIsDate = t.is_date ? PR_TRUE : PR_FALSE; if (mIsDate) { t.hour = 0; t.minute = 0; t.second = 0; } if (mIsValid) { t = icaltime_normalize(t); } mYear = static_cast<PRInt16>(t.year); mMonth = static_cast<PRInt16>(t.month - 1); mDay = static_cast<PRInt16>(t.day); mHour = static_cast<PRInt16>(t.hour); mMinute = static_cast<PRInt16>(t.minute); mSecond = static_cast<PRInt16>(t.second); if (tz) { mTimezone = tz; } else { mTimezone = cal::detectTimezone(t, nsnull); } #if defined(DEBUG) if (mTimezone) { if (t.is_utc) { #if 1 nsCOMPtr<calITimezone> utc_tz; nsCOMPtr<calITimezoneService> tzSvc = do_GetService(CAL_TIMEZONESERVICE_CONTRACTID); tzSvc->GetUTC(getter_AddRefs(utc_tz)); NS_ASSERTION(SameCOMIdentity(mTimezone, utc_tz), "UTC mismatch!"); #else NS_ASSERTION(SameCOMIdentity(mTimezone, cal::UTC()), "UTC mismatch!"); #endif } else if (!t.zone) { #if 1 nsCOMPtr<calITimezone> float_tz; nsCOMPtr<calITimezoneService> tzSvc = do_GetService(CAL_TIMEZONESERVICE_CONTRACTID); tzSvc->GetFloating(getter_AddRefs(float_tz)); NS_ASSERTION(SameCOMIdentity(mTimezone, float_tz), "floating mismatch!"); #else NS_ASSERTION(SameCOMIdentity(mTimezone, cal::floating()), "floating mismatch!"); #endif } else { nsCAutoString tzid; mTimezone->GetTzid(tzid); NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))), "tzid mismatch!"); } } #endif mWeekday = static_cast<PRInt16>(icaltime_day_of_week(t) - 1); mYearday = static_cast<PRInt16>(icaltime_day_of_year(t)); // mNativeTime: not moving the existing date to UTC, // but merely representing it a UTC-based way. t.is_date = 0; mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone()); }
nsresult EditorEventListener::Focus(nsIDOMEvent* aEvent) { NS_ENSURE_TRUE(aEvent, NS_OK); // Don't turn on selection and caret when the editor is disabled. if (mEditorBase->IsDisabled()) { return NS_OK; } // Spell check a textarea the first time that it is focused. SpellCheckIfNeeded(); if (!mEditorBase) { // In e10s, this can cause us to flush notifications, which can destroy // the node we're about to focus. return NS_OK; } nsCOMPtr<nsIDOMEventTarget> target; aEvent->GetTarget(getter_AddRefs(target)); nsCOMPtr<nsINode> node = do_QueryInterface(target); NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED); // If the target is a document node but it's not editable, we should ignore // it because actual focused element's event is going to come. if (node->IsNodeOfType(nsINode::eDOCUMENT) && !node->HasFlag(NODE_IS_EDITABLE)) { return NS_OK; } if (node->IsNodeOfType(nsINode::eCONTENT)) { // XXX If the focus event target is a form control in contenteditable // element, perhaps, the parent HTML editor should do nothing by this // handler. However, FindSelectionRoot() returns the root element of the // contenteditable editor. So, the editableRoot value is invalid for // the plain text editor, and it will be set to the wrong limiter of // the selection. However, fortunately, actual bugs are not found yet. nsCOMPtr<nsIContent> editableRoot = mEditorBase->FindSelectionRoot(node); // make sure that the element is really focused in case an earlier // listener in the chain changed the focus. if (editableRoot) { nsIFocusManager* fm = nsFocusManager::GetFocusManager(); NS_ENSURE_TRUE(fm, NS_OK); nsCOMPtr<nsIDOMElement> element; fm->GetFocusedElement(getter_AddRefs(element)); if (!element) { return NS_OK; } nsCOMPtr<nsIDOMEventTarget> originalTarget; aEvent->GetOriginalTarget(getter_AddRefs(originalTarget)); nsCOMPtr<nsIContent> originalTargetAsContent = do_QueryInterface(originalTarget); nsCOMPtr<nsIContent> focusedElementAsContent = do_QueryInterface(element); if (!SameCOMIdentity( focusedElementAsContent->FindFirstNonChromeOnlyAccessContent(), originalTargetAsContent->FindFirstNonChromeOnlyAccessContent())) { return NS_OK; } } } mEditorBase->OnFocus(target); nsCOMPtr<nsIPresShell> ps = GetPresShell(); NS_ENSURE_TRUE(ps, NS_OK); nsCOMPtr<nsIContent> focusedContent = mEditorBase->GetFocusedContentForIME(); IMEStateManager::OnFocusInEditor(ps->GetPresContext(), focusedContent, mEditorBase); return NS_OK; }