function Pos Override

本文介绍了一个使用Pascal语言中的汇编指令实现的字符串查找函数。该函数通过逐字符比较的方式,在源字符串中查找指定字符首次出现的位置。文章提供了完整的汇编代码示例,并展示了如何在Pascal程序中调用此函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

我正在编辑【Emmylua】代码,遇到了 【LuaException: Projects/AAAShare/ShiYans/XiaHeMoYaWoGouFengBiShu/Mission/UI/UIXiShouPaiXun/ui_xishoupaixun.lua:609: attempt to index a nil value (field '?')】 ,请帮我检查并改正错误点。我的原始代码如下: 【----@class UIXiShouPaiXun:UIBaseView2 local UIXiShouPaiXun = BaseClass("UIXiShouPaiXun", UIBaseView2) function UIXiShouPaiXun:ShuffleArray(t) if not t then return {} end for i = #t, 2, -1 do local j = math.random(i) t[i], t[j] = t[j], t[i] end return t end -- 创建完调用 function UIXiShouPaiXun:LoadCallBack() -- override --UINameTable init start --上面的七个位置 ---@type UnityEngine.GameObject self.upimg1 = self:FindObj("upimg1") ---@type UnityEngine.GameObject self.upimg2 = self:FindObj("upimg2") ---@type UnityEngine.GameObject self.upimg3 = self:FindObj("upimg3") ---@type UnityEngine.GameObject self.upimg4 = self:FindObj("upimg4") ---@type UnityEngine.GameObject self.upimg5 = self:FindObj("upimg5") ---@type UnityEngine.GameObject self.upimg6 = self:FindObj("upimg6") ---@type UnityEngine.GameObject self.upimg7 = self:FindObj("upimg7") --下面的七个位置 ---@type UnityEngine.GameObject self.downimg1 = self:FindObj("downimg1") ---@type UnityEngine.GameObject self.downimg2 = self:FindObj("downimg2") ---@type UnityEngine.GameObject self.downimg3 = self:FindObj("downimg3") ---@type UnityEngine.GameObject self.downimg4 = self:FindObj("downimg4") ---@type UnityEngine.GameObject self.downimg5 = self:FindObj("downimg5") ---@type UnityEngine.GameObject self.downimg6 = self:FindObj("downimg6") ---@type UnityEngine.GameObject self.downimg7 = self:FindObj("downimg7") --七张图片 ---@type UnityEngine.GameObject self.xiShouImg1 = self:FindObj("xiShouImg1") ---@type UnityEngine.GameObject self.xiShouImg2 = self:FindObj("xiShouImg2") ---@type UnityEngine.GameObject self.xiShouImg3 = self:FindObj("xiShouImg3") ---@type UnityEngine.GameObject self.xiShouImg4 = self:FindObj("xiShouImg4") ---@type UnityEngine.GameObject self.xiShouImg5 = self:FindObj("xiShouImg5") ---@type UnityEngine.GameObject self.xiShouImg6 = self:FindObj("xiShouImg6") ---@type UnityEngine.GameObject self.xiShouImg7 = self:FindObj("xiShouImg7") --提交按钮 ---@type UnityEngine.GameObject self.btn_TiJiao = self:FindObj("btn_TiJiao") --正确答案显示按钮 ---@type UnityEngine.GameObject self.btn_zhengQue = self:FindObj("btn_zhengQue") ---@type UnityEngine.GameObject self.btn_NextStep = self:FindObj("btn_zhengQue") ---@type UnityEngine.Canvas self.CanvasUp = self:FindObj("CanvasUp"):GetComponent(typeof(CS.UnityEngine.Canvas)) ---@type UnityEngine.UI.Image self.CorrectMark = self:FindObj("CorrectMark"):GetComponent(typeof(CS.UnityEngine.UI.Image)) ---@type UnityEngine.UI.Image self.WrongMark = self:FindObj("WrongMark"):GetComponent(typeof(CS.UnityEngine.UI.Image)) ---@type UnityEngine.UI.Image self.righttMark1 = self:FindObj("righttMark1") ---@type UnityEngine.UI.Image self.righttMark2 = self:FindObj("righttMark2") ---@type UnityEngine.UI.Image self.righttMark3 = self:FindObj("righttMark3") ---@type UnityEngine.UI.Image self.righttMark4 = self:FindObj("righttMark4") ---@type UnityEngine.UI.Image self.righttMark5 = self:FindObj("righttMark5") ---@type UnityEngine.UI.Image self.righttMark6 = self:FindObj("righttMark6") ---@type UnityEngine.UI.Image self.righttMark7 = self:FindObj("righttMark7") --UINameTable init end --UIVariableTable init start --UIVariableTable init end --self.testGo1 = MissionManager.Instance:GetGameObject("XXX") ---@type UnityEngine.GameObject[] self.upPositions = { self.upimg1, self.upimg2, self.upimg3, self.upimg4, self.upimg5, self.upimg6, self.upimg7 } ---@type UnityEngine.GameObject[] self.downPositions = { self.downimg1, self.downimg2, self.downimg3, self.downimg4, self.downimg5, self.downimg6, self.downimg7 } ---@type UnityEngine.GameObject[] self.images = { self.xiShouImg1, self.xiShouImg2, self.xiShouImg3, self.xiShouImg4, self.xiShouImg5, self.xiShouImg6, self.xiShouImg7 } ---@type UnityEngine.UI.Image[] self.rightMarks = {} self.rightMarks[1] = self.righttMark1:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[2] = self.righttMark2:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[3] = self.righttMark3:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[4] = self.righttMark4:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[5] = self.righttMark5:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[6] = self.righttMark6:GetComponent(typeof(CS.UnityEngine.UI.Image)) self.rightMarks[7] = self.righttMark7:GetComponent(typeof(CS.UnityEngine.UI.Image)) -- 初始化变量 self.imageStepMap = {} -- 图片到步骤的映射 self.positionToImage = {} -- 位置到图片的映射 self.imageToPosition = {} -- 图片到位置的映射 self.dragStartPositions = {} -- 拖拽起始位置 -- 设置图片的步骤映射 (1-7) for i, img in ipairs(self.images) do self.imageStepMap[img] = i end -- 初始化按钮状态 self:XianYin(self.btn_TiJiao, 0) self:XianYin(self.btn_zhengQue, 0) self:XianYin(self.btn_NextStep, 0) -- 初始化拖拽功能 self:InitDrag() -- 随机排列下方图片 self:ShuffleDownImages() -- 记录画布平面的Z位置 self.canvasZ = self.transform.position.z end -- 销毁前调用 function UIXiShouPaiXun:ReleaseCallBack() -- override --UINameTable delete start self.upimg1 = nil self.upimg2 = nil self.upimg3 = nil self.upimg4 = nil self.upimg5 = nil self.upimg6 = nil self.upimg7 = nil self.downimg1 = nil self.downimg2 = nil self.downimg3 = nil self.downimg4 = nil self.downimg5 = nil self.downimg6 = nil self.downimg7 = nil self.xiShouImg1 = nil self.xiShouImg2 = nil self.xiShouImg3 = nil self.xiShouImg4 = nil self.xiShouImg5 = nil self.xiShouImg6 = nil self.xiShouImg7 = nil self.btn_TiJiao = nil self.btn_zhengQue = nil self.CanvasUp = nil self.CorrectMark = nil self.WrongMark = nil self.righttMark1 = nil self.righttMark2 = nil self.righttMark3 = nil self.righttMark4 = nil self.righttMark5 = nil self.righttMark6 = nil self.righttMark7 = nil --UINameTable delete end --UIVariableTable delete start --UIVariableTable delete end self.upPositions = nil self.downPositions = nil self.images = nil self.rightMarks = nil self.imageStepMap = nil self.positionToImage = nil self.imageToPosition = nil self.dragStartPositions = nil self.canvasZ = nil end -- 打开后调用 function UIXiShouPaiXun:OpenCallBack() -- override --UIEventTable init start --点提交按钮的事件 self.onClickTiJiaoEvent = BindTool.Bind(self, self.OnClickTiJiao) self:ListenEvent("TiJiao", self.onClickTiJiaoEvent) --点正确答案按钮的事件 self.onClickZhengQueDaAnEvent = BindTool.Bind(self, self.OnClickZhengQueDaAn) self:ListenEvent("ZhengQueDaAn", self.onClickZhengQueDaAnEvent) --UIEventTable init end for _, masks in ipairs(self.rightMarks) do self:XianYin(masks.gameObject, 0) end end -- 关闭前调用 function UIXiShouPaiXun:CloseCallBack() -- override --UIEventTable delete start self:ClearEvent("TiJiao") self.onClickTiJiaoEvent = nil self:ClearEvent("ZhengQueDaAn") self.onClickZhengQueDaAnEvent = nil MissionManager.Instance:UnbindCustomBtn("下一步") --UIEventTable delete end end -- 刷新,使用Flush来触发此方法。 function UIXiShouPaiXun:OnFlush(param_list) -- override end -- 集中注册信息 function UIXiShouPaiXun:OnAddListener() -- override end -- 集中注销消息 function UIXiShouPaiXun:OnRemoveListener() -- override end ---@param key string ---@param saver Nirvana.MissionSystem.Save.Saver function UIXiShouPaiXun:Back(key, saver) --回退 --saver:ResetGameObject(key, self.testGo1) end ---@param key string ---@param saver Nirvana.MissionSystem.Save.Saver function UIXiShouPaiXun:Save(key, saver, ...) --保存 --saver:SaveGameObject(key, self.testGo1) end function UIXiShouPaiXun:SetParam(...) -- override -- 执行此方法的时候,请保证UI已经打开。 end function UIXiShouPaiXun:Start(...) -- override -- 开始 -- eg 1:直接完成 -- FWGlobalEventSystem:Fire(ShiYanEventType.OPERATE_OVER, self:GetName()) -- eg 2:申请交互 -- FWGlobalEventSystem:Fire(ShiYanEventType.TRY_INTERACT, self:GetName()) end function UIXiShouPaiXun:Imm(...) -- override -- 直接完成 FWGlobalEventSystem:Fire(ShiYanEventType.OPERATE_OVER, self:GetName()) end function UIXiShouPaiXun:Stop() -- override -- 停止 end function UIXiShouPaiXun:Continue() -- override -- eg 2:交互回调 --FWGlobalEventSystem:Fire(ShiYanEventType.OPERATE_OVER, self:GetName(),0,1) return false end function UIXiShouPaiXun:Guide(...) -- override return false end function UIXiShouPaiXun:XianYin(object, a) if object then -- 添加空值检查 object:SetActive(a == 1) end end function UIXiShouPaiXun:InitDrag() for _, img in ipairs(self.images) do self:AddDragEvents(img) end end function UIXiShouPaiXun:AddDragEvents(img) -- 获取或添加EventTrigger组件 local eventTrigger = img:GetComponent(typeof(CS.UnityEngine.EventSystems.EventTrigger)) if eventTrigger == nil then eventTrigger = img:AddComponent(typeof(CS.UnityEngine.EventSystems.EventTrigger)) else -- 清除现有事件 eventTrigger.triggers:Clear() end -- 开始拖拽事件 local beginEntry = CS.UnityEngine.EventSystems.EventTrigger.Entry() beginEntry.eventID = CS.UnityEngine.EventSystems.EventTriggerType.BeginDrag beginEntry.callback:AddListener(function() self:OnBeginDrag(img) end) eventTrigger.triggers:Add(beginEntry) -- 拖拽中事件 local dragEntry = CS.UnityEngine.EventSystems.EventTrigger.Entry() dragEntry.eventID = CS.UnityEngine.EventSystems.EventTriggerType.Drag dragEntry.callback:AddListener(function() self:OnDrag(img) end) eventTrigger.triggers:Add(dragEntry) -- 结束拖拽事件 local endEntry = CS.UnityEngine.EventSystems.EventTrigger.Entry() endEntry.eventID = CS.UnityEngine.EventSystems.EventTriggerType.EndDrag endEntry.callback:AddListener(function() self:OnEndDrag(img) end) eventTrigger.triggers:Add(endEntry) end -- 随机排列下方图片 function UIXiShouPaiXun:ShuffleDownImages() -- 重置所有映射关系 self.positionToImage = {} self.imageToPosition = {} local t = { 1, 2, 3, 4, 5, 6, 7 } -- 创建1-7的随机顺序 local randomOrder = self:ShuffleArray(t) -- 将图片放置到随机位置 for i, img in ipairs(self.images) do local pos = self.downPositions[randomOrder[i]] img.transform:SetParent(pos.transform) img.transform.localPosition = Vector3.zero img.transform:SetAsLastSibling() -- 确保显示在最上层 end end -- 开始拖拽处理 function UIXiShouPaiXun:OnBeginDrag(img) -- 记录当前拖拽的图片 self.draggingImage = img -- 记录拖拽前的父对象和位置 self.dragStartParent = img.transform.parent self.dragStartPosition = img.transform.localPosition -- 记录原始Z坐标 self.originalZ = img.transform.position.z -- 提升层级到最上层 img.transform:SetParent(self.transform) img.transform:SetAsLastSibling() end -- 拖拽中处理(跟随鼠标移动) function UIXiShouPaiXun:OnDrag(img) -- 获取鼠标位置 local mousePos = CS.UnityEngine.Input.mousePosition -- 获取画布相机 local camera = self.CanvasUp.worldCamera if camera == nil then camera = CS.UnityEngine.Camera.main end -- 确保有相机 if camera then -- 计算从相机到画布平面的距离 local distance = math.abs(camera.transform.position.z - self.canvasZ) -- 将屏幕坐标转换为世界坐标 local worldPos = camera:ScreenToWorldPoint( CS.UnityEngine.Vector3(mousePos.x, mousePos.y, distance) ) -- 保持原始Z坐标 worldPos = CS.UnityEngine.Vector3(worldPos.x, worldPos.y, self.originalZ) img.transform.position = worldPos end end -- 结束拖拽处理 function UIXiShouPaiXun:OnEndDrag(img) local hitPosition = nil -- 检查上方位置 for _, pos in ipairs(self.upPositions) do if self:IsPointInRect(pos, img) then hitPosition = pos break end end -- 检查下方位置 if not hitPosition then for _, pos in ipairs(self.downPositions) do if self:IsPointInRect(pos, img) then hitPosition = pos break end end end if hitPosition then self:PlaceImageToPosition(img, hitPosition) else -- 返回原始位置 img.transform:SetParent(self.dragStartParent) img.transform.localPosition = self.dragStartPosition end self.draggingImage = nil self:CheckAllPlaced() end function UIXiShouPaiXun:IsPointInRect(position, img) if not position or not img then return false end local rectTransform = position:GetComponent(typeof(CS.UnityEngine.RectTransform)) if not rectTransform then return false end local camera = self.CanvasUp.worldCamera if not camera then camera = CS.UnityEngine.Camera.main if not camera then -- 如果还是没有相机,返回false return false end end local imgRectTransform = img:GetComponent(typeof(CS.UnityEngine.RectTransform)) if not imgRectTransform then return false end local imgCenter = imgRectTransform.position local screenPos = camera:WorldToScreenPoint(imgCenter) -- 确保坐标有效(避免相机在物体后方的情况) if screenPos.z <= 0 then return false end local screenPos2 = CS.UnityEngine.Vector2(screenPos.x, screenPos.y) return CS.UnityEngine.RectTransformUtility.RectangleContainsScreenPoint( rectTransform, screenPos2, camera ) end -- 将图片放置到指定位置 function UIXiShouPaiXun:PlaceImageToPosition(img, position) -- 如果位置已有图片,交换位置 if self.positionToImage[position] then local otherImg = self.positionToImage[position] self:SwapImages(img, otherImg) else -- 更新映射关系 if self.imageToPosition[img] then self.positionToImage[self.imageToPosition[img]] = nil end self.positionToImage[position] = img self.imageToPosition[img] = position -- 设置新父对象和位置 img.transform:SetParent(position.transform) img.transform.localPosition = Vector3.zero -- 关键:设置为第一个子节点(底层) img.transform:SetAsFirstSibling() end end -- 交换两个图片的位置 function UIXiShouPaiXun:SwapImages(img1, img2) local pos1 = self.imageToPosition[img1] local pos2 = self.imageToPosition[img2] -- 更新映射关系 self.positionToImage[pos1] = img2 self.positionToImage[pos2] = img1 self.imageToPosition[img1] = pos2 self.imageToPosition[img2] = pos1 -- 交换父对象 img1.transform:SetParent(pos2.transform) img1.transform.localPosition = Vector3.zero img1.transform:SetAsFirstSibling() img2.transform:SetParent(pos1.transform) img2.transform.localPosition = Vector3.zero img2.transform:SetAsFirstSibling() end -- 检查所有上方位置是否都已放置图片 function UIXiShouPaiXun:CheckAllPlaced() local allPlaced = true -- 遍历所有上方位置 for _, pos in ipairs(self.upPositions) do if not self.positionToImage[pos] then allPlaced = false break end end -- 根据检查结果更新提交按钮状态 if self.btn_TiJiao then self.btn_TiJiao:SetActive(allPlaced) end end -- 点击提交按钮事件处理 function UIXiShouPaiXun:OnClickTiJiao() -- 禁用所有拖拽功能 for _, img in ipairs(self.images) do if img then local eventTrigger = img:GetComponent(typeof(CS.UnityEngine.EventSystems.EventTrigger)) if eventTrigger then eventTrigger.enabled = false end end end -- 检查每个位置是否正确 local allCorrect = true for i, pos in ipairs(self.upPositions) do local img = self.positionToImage[pos] if img and self.imageStepMap[img] == i then -- 位置正确,显示正确标记 self:ShowMark(img, true, i) else -- 位置错误,显示错误标记 self:ShowMark(img, false) allCorrect = false end end -- 更新按钮状态 if self.btn_TiJiao then self.btn_TiJiao:SetActive(false) end if allCorrect then -- 全部正确,显示下一步按钮 self:ShowNextStepButton() else -- 存在错误,显示正确答案按钮 if self.btn_zhengQue then self.btn_zhengQue:SetActive(true) end end end -- 在图片上显示正确/错误标记 function UIXiShouPaiXun:ShowMark(img, isCorrect, num) if not img then return end -- 根据正确性选择标记名称 self.rightMarks[num].sprite = isCorrect and self.CorrectMark.sprite or self.WrongMark.sprite if mark then self:XianYin(self.rightMarks[num].gameObject, 1) end end -- 隐藏所有图片上的标记 function UIXiShouPaiXun:HideAllMarks() for i, img in ipairs(self.images) do if img then ---- 查找正确标记 --local correctMark = img.transform:Find("CorrectMark") --if correctMark then -- correctMark.gameObject:SetActive(false) --end -- ---- 查找错误标记 --local wrongMark = img.transform:Find("WrongMark") --if wrongMark then -- wrongMark.gameObject:SetActive(false) --end self:XianYin(self.rightMarks[i].gameObject, 0) end end end -- 点击"正确答案"按钮事件处理 function UIXiShouPaiXun:OnClickZhengQueDaAn() -- 隐藏下方位置 for _, pos in ipairs(self.downPositions) do if pos then pos:SetActive(false) end end -- 隐藏所有标记 self:HideAllMarks() -- 将图片移动到正确位置 for i, pos in ipairs(self.upPositions) do if pos then local correctImg = self.images[i] -- 获取对应步骤的图片 if correctImg then correctImg.transform:SetParent(pos.transform) correctImg.transform.localPosition = Vector3.zero end end end ---- 更新按钮状态 --if self.btn_zhengQue then -- self.btn_zhengQue:SetActive(false) --end self:XianYin(self.btn_zhengQue.gameObject, 0) -- 显示下一步按钮 self:ShowNextStepButton() end function UIXiShouPaiXun:ShowNextStepButton() if self.btn_NextStep then self.btn_NextStep:SetActive(true) end MissionManager.Instance:BindCustomBtn("下一步", function() self:OnClickNextStep() end) end -- 点击下一步按钮事件处理 function UIXiShouPaiXun:OnClickNextStep() -- 触发完成事件 FWGlobalEventSystem:Fire(ShiYanEventType.OPERATE_OVER, self:GetName()) end return UIXiShouPaiXun;】
06-04
详细分析解释一下chromium源码中的下面的函数: class OmniboxViewViews : public OmniboxView, public views::Textfield, #if BUILDFLAG(IS_CHROMEOS) public ash::input_method::InputMethodManager::CandidateWindowObserver, #endif public views::TextfieldController, public ui::CompositorObserver, public TemplateURLServiceObserver { METADATA_HEADER(OmniboxViewViews, views::Textfield) public: // Max width of the gradient mask used to smooth ElideAnimation edges. static const int kSmoothingGradientMaxWidth = 15; OmniboxViewViews(std::unique_ptr<OmniboxClient> client, bool popup_window_mode, LocationBarView* location_bar_view, const gfx::FontList& font_list); OmniboxViewViews(const OmniboxViewViews&) = delete; OmniboxViewViews& operator=(const OmniboxViewViews&) = delete; ~OmniboxViewViews() override; // Initialize, create the underlying views, etc. void Init(); // Exposes the RenderText for tests. #if defined(UNIT_TEST) gfx::RenderText* GetRenderText() { return views::Textfield::GetRenderText(); } #endif // For use when switching tabs, this saves the current state onto the tab so // that it can be restored during a later call to Update(). void SaveStateToTab(content::WebContents* tab); // Called when the window's active tab changes. void OnTabChanged(const content::WebContents* web_contents); // Called to clear the saved state for |web_contents|. void ResetTabState(content::WebContents* web_contents); // Installs the placeholder text with the name of the current default search // provider. For example, if Google is the default search provider, this shows // "Search Google or type a URL" when the Omnibox is empty and unfocused. void InstallPlaceholderText(); // Indicates if the cursor is at the end of the input. Requires that both // ends of the selection reside there. bool GetSelectionAtEnd() const; // Returns the width in pixels needed to display the current text. The // returned value includes margins. int GetTextWidth() const; // Returns the width in pixels needed to display the current text unelided. int GetUnelidedTextWidth() const; // Returns the omnibox's width in pixels. int GetWidth() const; // OmniboxView: void EmphasizeURLComponents() override; void Update() override; std::u16string GetText() const override; using OmniboxView::SetUserText; void SetUserText(const std::u16string& text, bool update_popup) override; void SetWindowTextAndCaretPos(const std::u16string& text, size_t caret_pos, bool update_popup, bool notify_text_changed) override; void SetAdditionalText(const std::u16string& additional_text) override; void EnterKeywordModeForDefaultSearchProvider() override; bool IsSelectAll() const override; void GetSelectionBounds(std::u16string::size_type* start, std::u16string::size_type* end) const override; void SelectAll(bool reversed) override; void RevertAll() override; void SetFocus(bool is_user_initiated) override; bool IsImeComposing() const override; gfx::NativeView GetRelativeWindowForPopup() const override; bool IsImeShowingPopup() const override; // views::Textfield: gfx::Size GetMinimumSize() const override; bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMouseDragged(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override; void OnPaint(gfx::Canvas* canvas) override; void ExecuteCommand(int command_id, int event_flags) override; void OnInputMethodChanged() override; void AddedToWidget() override; void RemovedFromWidget() override; std::u16string GetLabelForCommandId(int command_id) const override; bool IsCommandIdEnabled(int command_id) const override; // For testing only. OmniboxPopupView* GetPopupViewForTesting() const; protected: // OmniboxView: void UpdateSchemeStyle(const gfx::Range& range) override; // views::Textfield: void OnThemeChanged() override; bool IsDropCursorForInsertion() const override; // Wrappers around Textfield methods that tests can override. virtual void ApplyColor(SkColor color, const gfx::Range& range); virtual void ApplyStyle(gfx::TextStyle style, bool value, const gfx::Range& range); private: friend class TestingOmniboxView; FRIEND_TEST_ALL_PREFIXES(OmniboxPopupViewViewsTest, EmitAccessibilityEvents); // TODO(tommycli): Remove the rest of these friends after porting these // browser tests to unit tests. FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FriendlyAccessibleLabel); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, DoNotNavigateOnDrop); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, AyncDropCallback); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, AccessibleTextSelectBoundTest); enum class UnelisionGesture { HOME_KEY_PRESSED, MOUSE_RELEASE, OTHER, }; // Update the field with |text| and set the selection. |ranges| should not be // empty; even text with no selections must have at least 1 empty range in // |ranges| to indicate the cursor position. void SetTextAndSelectedRange(const std::u16string& text, const gfx::Range& selection); // Returns the selected text. std::u16string_view GetSelectedText() const; void UpdateAccessibleTextSelection() override; // Paste text from the clipboard into the omnibox. // Textfields implementation of Paste() pastes the contents of the clipboard // as is. We want to strip whitespace and other things (see GetClipboardText() // for details). The function invokes OnBefore/AfterPossibleChange() as // necessary. void OnOmniboxPaste(); // Handle keyword hint tab-to-search and tabbing through dropdown results. bool HandleEarlyTabActions(const ui::KeyEvent& event); void ClearAccessibilityLabel(); void SetAccessibilityLabel(const std::u16string& display_text, const AutocompleteMatch& match, bool notify_text_changed) override; // Returns true if the user text was updated with the full URL (without // steady-state elisions). |gesture| is the user gesture causing unelision. bool UnapplySteadyStateElisions(UnelisionGesture gesture); #if BUILDFLAG(IS_MAC) void AnnounceFriendlySuggestionText(); #endif // Get the preferred text input type, this checks the IME locale on Windows. ui::TextInputType GetPreferredTextInputType() const; // OmniboxView: void SetCaretPos(size_t caret_pos) override; void UpdatePopup() override; void ApplyCaretVisibility() override; void OnTemporaryTextMaybeChanged(const std::u16string& display_text, const AutocompleteMatch& match, bool save_original_selection, bool notify_text_changed) override; void OnInlineAutocompleteTextMaybeChanged( const std::u16string& user_text, const std::u16string& inline_autocompletion) override; void OnInlineAutocompleteTextCleared() override; void OnRevertTemporaryText(const std::u16string& display_text, const AutocompleteMatch& match) override; void OnBeforePossibleChange() override; bool OnAfterPossibleChange(bool allow_keyword_ui_change) override; void OnKeywordPlaceholderTextChange() override; gfx::NativeView GetNativeView() const override; void ShowVirtualKeyboardIfEnabled() override; void HideImeIfNeeded() override; int GetOmniboxTextLength() const override; void SetEmphasis(bool emphasize, const gfx::Range& range) override; // views::View void OnMouseMoved(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override; // views::Textfield: bool IsItemForCommandIdDynamic(int command_id) const override; void OnGestureEvent(ui::GestureEvent* event) override; bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; bool HandleAccessibleAction(const ui::AXActionData& action_data) override; void OnFocus() override; void OnBlur() override; std::u16string GetSelectionClipboardText() const override; void DoInsertChar(char16_t ch) override; bool IsTextEditCommandEnabled(ui::TextEditCommand command) const override; void ExecuteTextEditCommand(ui::TextEditCommand command) override; bool ShouldShowPlaceholderText() const override; void UpdateAccessibleValue() override; // ash::input_method::InputMethodManager::CandidateWindowObserver: #if BUILDFLAG(IS_CHROMEOS) void CandidateWindowOpened( ash::input_method::InputMethodManager* manager) override; void CandidateWindowClosed( ash::input_method::InputMethodManager* manager) override; #endif // views::TextfieldController: void ContentsChanged(views::Textfield* sender, const std::u16string& new_contents) override; bool HandleKeyEvent(views::Textfield* sender, const ui::KeyEvent& key_event) override; void OnBeforeUserAction(views::Textfield* sender) override; void OnAfterUserAction(views::Textfield* sender) override; void OnAfterCutOrCopy(ui::ClipboardBuffer clipboard_buffer) override; void OnWriteDragData(ui::OSExchangeData* data) override; void OnGetDragOperationsForTextfield(int* drag_operations) override; void AppendDropFormats( int* formats, std::set<ui::ClipboardFormatType>* format_types) override; ui::mojom::DragOperation OnDrop(const ui::DropTargetEvent& event) override; views::View::DropCallback CreateDropCallback( const ui::DropTargetEvent& event) override; void UpdateContextMenu(ui::SimpleMenuModel* menu_contents) override; // ui::SimpleMenuModel::Delegate: bool IsCommandIdChecked(int id) const override; // ui::CompositorObserver: void OnCompositingDidCommit(ui::Compositor* compositor) override; void OnCompositingStarted(ui::Compositor* compositor, base::TimeTicks start_time) override; void OnDidPresentCompositorFrame( uint32_t frame_token, const gfx::PresentationFeedback& feedback) override; void OnCompositingShuttingDown(ui::Compositor* compositor) override; // TemplateURLServiceObserver: void OnTemplateURLServiceChanged() override; // Permits launch of the external protocol handler after user actions in // the omnibox. The handler needs to be informed that omnibox input should // always be considered "user gesture-triggered", lest it always return BLOCK. void PermitExternalProtocolHandler(); // Drops dragged text and updates `output_drag_op` accordingly. void PerformDrop(const ui::DropTargetEvent& event, ui::mojom::DragOperation& output_drag_op, std::unique_ptr<ui::LayerTreeOwner> drag_image_layer_owner); // Helper method to construct part of the context menu. void MaybeAddSendTabToSelfItem(ui::SimpleMenuModel* menu_contents); // Called when the popup view becomes visible. void OnPopupOpened(); // Helper for updating placeholder color depending on whether its a keyword or // DSE placeholder. void UpdatePlaceholderTextColor(); // When true, the location bar view is read only and also is has a slightly // different presentation (smaller font size). This is used for popups. bool popup_window_mode_; // Owns either an OmniboxPopupViewViews or an OmniboxPopupViewWebUI. std::unique_ptr<OmniboxPopupView> popup_view_; base::CallbackListSubscription popup_view_opened_subscription_; // Selection persisted across temporary text changes, like popup suggestions. gfx::Range saved_temporary_selection_; // Holds the user's selection across focus changes. There is only a saved // selection if this range IsValid(). gfx::Range saved_selection_for_focus_change_; // Tracking state before and after a possible change. State state_before_change_; bool ime_composing_before_change_ = false; // |location_bar_view_| can be NULL in tests. raw_ptr<LocationBarView> location_bar_view_; #if BUILDFLAG(IS_CHROMEOS) // True if the IME candidate window is open. When this is true, we want to // avoid showing the popup. So far, the candidate window is detected only // on Chrome OS. bool ime_candidate_window_open_ = false; #endif // True if any mouse button is currently depressed. bool is_mouse_pressed_ = false; // Applies a minimum threshold to drag events after unelision. Because the // text shifts after unelision, we don't want unintentional mouse drags to // change the selection. bool filter_drag_events_for_unelision_ = false; // Should we select all the text when we see the mouse button get released? // We select in response to a click that focuses the omnibox, but we defer // until release, setting this variable back to false if we saw a drag, to // allow the user to select just a portion of the text. bool select_all_on_mouse_release_ = false; // Indicates if we want to select all text in the omnibox when we get a // GESTURE_TAP. We want to select all only when the textfield is not in focus // and gets a tap. So we use this variable to remember focus state before tap. bool select_all_on_gesture_tap_ = false; // Whether the user should be notified if the clipboard is restricted. bool show_rejection_ui_if_any_ = false; // Keep track of the word that would be selected if URL is unelided between // a single and double click. This is an edge case where the elided URL is // selected. On the double click, unelision is performed in between the first // and second clicks. This results in both the wrong word to be selected and // the wrong selection length. For example, if example.com is shown and you // try to double click on the "x", it unelides to https://example.com after // the first click, resulting in "https" being selected. size_t next_double_click_selection_len_ = 0; size_t next_double_click_selection_offset_ = 0; // The time of the first character insert operation that has not yet been // painted. Used to measure omnibox responsiveness with a histogram. base::TimeTicks insert_char_time_; // The state machine for logging the Omnibox.CharTypedToRepaintLatency // histogram. enum { NOT_ACTIVE, // Not currently tracking a char typed event. CHAR_TYPED, // Character was typed. ON_PAINT_CALLED, // Character was typed and OnPaint() called. COMPOSITING_COMMIT, // Compositing was committed after OnPaint(). COMPOSITING_STARTED, // Compositing was started. } latency_histogram_state_; // The currently selected match, if any, with additional labelling text // such as the document title and the type of search, for example: // "Google https://google.com location from bookmark", or // "cats are liquid search suggestion". std::u16string friendly_suggestion_text_; // The number of added labelling characters before editable text begins. // For example, "Google https://google.com location from history", // this is set to 7 (the length of "Google "). int friendly_suggestion_text_prefix_length_; base::ScopedObservation<ui::Compositor, ui::CompositorObserver> scoped_compositor_observation_{this}; base::ScopedObservation<TemplateURLService, TemplateURLServiceObserver> scoped_template_url_service_observation_{this}; PrefChangeRegistrar pref_change_registrar_; base::WeakPtrFactory<OmniboxViewViews> weak_factory_{this}; };
最新发布
08-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值