Document processing method and apparatus, device, and storage medium
By traversing and copying nodes in the DOM tree of the document to be browsed, paginated content is generated, which solves the problem of lag during document loading and improves document processing efficiency and reading experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-11-29
- Publication Date
- 2026-05-29
AI Technical Summary
Existing technologies are prone to causing processing lag and reducing document processing efficiency when loading large amounts of document content.
By traversing the original DOM tree of the document to be browsed and copying the traversed nodes to the target DOM tree, paginated content is generated, supporting various complex document formats and interactive requirements.
It enables flexible pagination of documents, reduces page lag, and improves the reading experience and document loading efficiency.
Smart Images

Figure CN122113849A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a document processing method, apparatus, device, and storage medium. Background Technology
[0002] With the continuous development of information technology, documents (such as web pages and emails) have become a major source of daily communication and information acquisition. However, as document content continues to increase, existing technologies require the complete loading of document content before display, which can easily cause processing lag and reduce document processing efficiency. Summary of the Invention
[0003] This application provides a document processing method, apparatus, device, and storage medium, which can improve document loading efficiency and has high applicability.
[0004] On one hand, embodiments of this application provide a document processing method, the method comprising: Get the document to be viewed; In response to the browsing trigger operation, the document content of the document to be browsed is displayed in pages in the document display area; The pages used to display document content in the aforementioned document display area are generated based on the following method: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the newly added nodes during each node traversal of the target DOM tree.
[0005] On the other hand, embodiments of this application provide a document processing apparatus, which includes: The document transfer module is used to acquire the document to be viewed; The document display module is used to respond to browsing trigger operations and display the document content of the document to be browsed in pages in the document display area; The page used to display document content in the aforementioned document display area is generated by the aforementioned document explicit module in the following way: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the nodes added during each node traversal of the target DOM tree. On the other hand, embodiments of this application provide an electronic device, including a processor and a memory, which are interconnected. The aforementioned memory is used to store computer programs; The processor described above is used to execute the document processing method provided in the embodiments of this application when the computer program described above is invoked.
[0006] On the other hand, embodiments of this application provide a computer-readable storage medium storing a computer program that is executed by a processor to implement the document processing method provided in embodiments of this application.
[0007] On the other hand, embodiments of this application provide a computer program product, which includes a computer program that, when executed by a processor, implements the document processing method provided in embodiments of this application.
[0008] In this embodiment, by traversing the original DOM tree of the document to be browsed and copying the traversed nodes to the target DOM tree to generate paginated content, long documents can be flexibly divided into multiple easy-to-read and manage pages, which conforms to the user's reading habits. It can also reduce page lag or crashes caused by loading a large amount of content at once, thereby improving the reading experience and document loading efficiency.
[0009] Furthermore, since the document processing method provided in this application is based on the DOM tree, it can support various complex document formats and interactive requirements. Whether a document contains a large amount of text, images, tables, or multimedia elements such as videos, this technical solution can perform paginated display and processing, further improving document processing efficiency. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a schematic diagram of the network structure provided in an embodiment of this application; Figure 2 This is a flowchart illustrating the document processing method provided in an embodiment of this application; Figure 3 This is one of the schematic diagrams of a scenario for triggering page turning provided in the embodiments of this application; Figure 4 This is the second schematic diagram of a scenario for triggering page turning provided in the embodiments of this application; Figure 5 This is a schematic diagram of the page generation process provided in an embodiment of this application; Figure 6 This is a schematic diagram of the node traversal principle provided in the embodiments of this application; Figure 7 This is a flowchart illustrating the display page provided in an embodiment of this application; Figure 8 This is one of the schematic diagrams of the node trimming process provided in the embodiments of this application; Figure 9 This is the second schematic diagram of the node trimming process provided in the embodiments of this application; Figure 10 This is the third schematic diagram of the node trimming process provided in the embodiments of this application; Figure 11 This is one of the scenario diagrams for triggering document editing provided in the embodiments of this application; Figure 12 This is the second schematic diagram of a scenario for triggering document editing provided in the embodiments of this application; Figure 13 This is a schematic diagram of a forwarding document scenario provided in an embodiment of this application; Figure 14 This is a schematic diagram illustrating the generation of the target DOM tree according to an embodiment of this application; Figure 15 This is a diagram illustrating the comparison of document loading times provided in an embodiment of this application; Figure 16 This is a schematic diagram comparing rendering times provided in an embodiment of this application; Figure 17 This is a diagram showing the comparison of the time taken to obtain edited content according to an embodiment of this application; Figure 18 This is a schematic diagram of the structure of the document processing device provided in the embodiments of this application; Figure 19 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0012] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0013] This application provides a document processing method applicable to the field of computer technology, used to improve the efficiency of document loading, document browsing, document editing, and document forwarding processes. See also Figure 1 , Figure 1 This is a schematic diagram of the network structure provided in an embodiment of this application. For example... Figure 1 As shown, after acquiring the document to be viewed, device 10 can display the document content in pages within the document display area. For example, assuming the document to be viewed is an email document, after acquiring the email document, device 10 can open the email document on the screen and display the email content in pages within the document display area.
[0014] The page used to display document content in the document display area of device 10 is generated by device 10 based on the following method: Device 10 performs document parsing on the document to be viewed and determines the original Document Object Model (DOM) tree of the document to be viewed.
[0015] Furthermore, device 10 performs at least one node traversal on the original DOM tree, copying the nodes traversed in each traversal to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each traversal constitute the document content included in at least one page. In this case, device 10 can generate at least one page based on the document elements corresponding to the nodes newly added in each node traversal of the target DOM tree, thereby achieving paginated display of the document content to be viewed.
[0016] Among them, device 10 can obtain documents to be viewed from a server or other terminal devices, such as downloading documents to be viewed from a server or receiving documents to be viewed sent by other terminal devices.
[0017] Among them, the server can be an independent physical server, such as a video server or a streaming media server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.
[0018] Among them, device 10 is a terminal device with display function. In this embodiment of the application, the terminal device can be a smartphone, tablet computer, laptop computer, desktop computer (including monitor), smartwatch, vehicle terminal, aircraft, smart home appliance (such as smart TV) or wearable device, etc.
[0019] The documents involved in this application embodiment can be web pages, emails, and other media information including rich text, such as text containing formatting information, such as font styles (bold, italic, etc.), colors, hyperlinks, images, tables, and other multi-element media information, which are not limited here.
[0020] In this application, the document format involved in the embodiments can be any format that can construct a DOM tree, such as a Hyper Text Markup Language (HTML) document, an Extensible Markup Language (XML) document, or other markup language documents based on XML or HTML, such as an Extensible Hyper Text Markup Language (XHTML) document, etc., without any limitation.
[0021] HTML is the standard markup language used to create web pages and web applications. XML is a markup language used to store and transmit data; similar to HTML, XML documents can also build DOM trees. XHTML is a more rigorous version of HTML, combining the ease of use of HTML with the structured nature of XML. XHTML documents can also build DOM trees.
[0022] In this embodiment, the DOM tree (Document Object Model tree) is an object model that represents web page content in a tree structure, defining the document's structure, style, and content. It organizes the various elements, text, and attributes in the document into a structure that can be accessed and manipulated by a programming language (usually JavaScript).
[0023] Each element in a document can be viewed as a node in the DOM tree, where nodes represent objects within the document being viewed. Nodes in the DOM tree are of various types, including element nodes, text nodes, attribute nodes, and document nodes. Element nodes are one of the fundamental building blocks of a document, representing tags in an HTML or XML document. Each element node corresponds to a tag in the document (e.g., ...). 、 , Document nodes (e.g., `<document>` elements) can contain other nodes (such as text nodes, attribute nodes, or other element nodes). Attribute nodes are a specific type of node associated with an element node and are used to represent the element's attributes. Attribute nodes contain additional information about the element, such as class name, ID, style, data attributes, etc. Text nodes represent the text content within an element; document nodes represent the root node of the entire document, the `<document>` element.
[0024] In the DOM tree, nodes are organized hierarchically to form a tree structure. Each node can have multiple child nodes, and each child node has a parent node. This hierarchical relationship allows developers to navigate through the node hierarchy, easily accessing and manipulating various elements within the document. Through the DOM tree, developers can conveniently access and manipulate the content of HTML or XML documents. They can obtain information such as the values, attributes, and styles of specific elements, or modify the document's content, structure, and styles, through the node hierarchy.
[0025] It should be noted that the document processing method provided in this application embodiment can be jointly executed by a server or a terminal device, such as the server executing the page generation process and the terminal device executing the page display process. Alternatively, the document processing method provided in this application embodiment can also be executed by the terminal device alone, and this is not limited here. See also Figure 2 , Figure 2 This is a flowchart illustrating the document processing method provided in an embodiment of this application. For example... Figure 2 As shown in the illustration, the document processing method provided in this application embodiment is described using a terminal device as an example. The method may include the following steps: S21, retrieve the document to be viewed.
[0026] In some feasible implementations, the document to be browsed can be the document data of the webpage currently being requested. For example, after accessing a certain URL via an HTTP request, the document data returned by the server corresponding to the accessed URL can be received, and this document data is the document to be browsed.
[0027] Optionally, the document to be viewed can also be document data obtained from other objects, such as email data, or rich text data sent by other objects, etc., without any restrictions.
[0028] It should be noted that the embodiments of this application do not limit the method of obtaining the document to be viewed or the specific form of the document to be viewed. The specific method can be determined according to the actual application scenario requirements.
[0029] S22, in response to the browsing trigger operation, the document content of the document to be browsed is displayed in pages in the document display area.
[0030] In some feasible implementations, the first page of the document to be viewed can be generated and displayed in the document display area in response to a browsing trigger operation on the document to be viewed.
[0031] Furthermore, during document browsing, in response to page-turning triggers for the document to be browsed, the document content of the next page corresponding to the current page can be generated and displayed in the document display area.
[0032] Optionally, in response to a browsing trigger operation for the document to be viewed, the first page of the document content to be viewed can be generated and displayed in the document display area. During the browsing of the first page of the document content, the content of each subsequent page of the document can be generated, and then in response to a page-turning trigger operation for any page, the content of the next page of the document to be viewed corresponding to the current page can be displayed in the document display area.
[0033] Optionally, in response to a browsing trigger operation for the document to be browsed, the first K pages of the document content to be browsed can be generated, and the first page of the document content to be browsed can be displayed in the document display area. During the browsing of the first K-1 pages, in response to a page-turning trigger operation, the next page of the document content for the current page can be displayed in the document display area. At the same time, during the browsing of the first K pages of the document content, the content of each page after page K can be generated, and then when browsing to page K, in response to a page-turning trigger operation, the next page of the document content after page K can be displayed in the document display area, and page-turning display of document content can be achieved during the flow of document content on any page after page K.
[0034] Where K can be an integer greater than 1.
[0035] The document display area, which displays document content on the page, can be implemented using the WebView component. WebView is a component for displaying web page content; it can be considered a lightweight browser control. It uses WebKit as its rendering engine to display web pages, including web page content, HTML files, and web forms, and supports operations such as zooming in and out, performing text searches, and navigation. Furthermore, WebView can handle interactive operations on web pages, such as link clicks, form submissions, and JavaScript execution.
[0036] In some feasible implementations, the page-turning trigger operation described above can be a touch operation collected through the page-turning touch button. For example... Figure 3 As shown, when displaying any page of the document to be viewed in the document display area, if a touch operation (such as a click) is detected on the "Next Page" button, it can be determined that the next page of the document content needs to be displayed. In this case, the next page of the document content can be generated and displayed in the document display area.
[0037] Alternatively, the page-turning trigger operation mentioned above can also be an automatic page-turning operation triggered when the currently viewed page is scrolled to the bottom of the document display area. For example... Figure 4 As shown, during the process of displaying any page of the document to be viewed in the document display area, the viewer can control the current page to slide down by swiping up. When the current page slides to the bottom of the document display area, it can be considered that a page-turning trigger operation has been detected. At this time, the next page of document content can be generated and displayed in the document display area.
[0038] Alternatively, the page-turning trigger operation mentioned above can also be a gesture operation for page turning obtained through the camera (such as waving to the right), or a gesture operation for page turning obtained based on the document display interface (such as swiping to the right), etc. The specific method can be determined based on the actual application scenario requirements, and there are no restrictions here.
[0039] Based on the above pagination display method, the loading time of the document to be viewed can be shortened, thereby enabling the document to be viewed to be displayed quickly and improving document processing efficiency.
[0040] For the generation method of each page in the document display area, please refer to [link / reference]. Figure 5 , Figure 5 This is a schematic diagram of the page generation process provided in an embodiment of this application. For example... Figure 5 As shown, the page generation method may include the following steps: S51, determine the original DOM tree of the document to be browsed.
[0041] In some feasible implementations, after obtaining the document to be viewed, document parsing can be performed on the document to be viewed to segment the document into different document elements using a lexical analyzer.
[0042] Furthermore, a parser is used to convert document elements into a tree structure. This involves understanding the structure and relationships of the document being browsed and constructing the nodes of the DOM tree based on these relationships. Further, based on the parsing results, the document node (Document node) is used as the root node of the original DOM tree, and other nodes are added to the tree as its child nodes. Each document element in the document being browsed corresponds to an element node in the DOM tree, while element attributes correspond to attribute nodes, and text content is added as text nodes under the corresponding element nodes.
[0043] Based on this, the original DOM tree of the document to be browsed can be generated and stored as a virtual DOM tree in memory or cache. At this point, the generated original DOM tree is not visible to the browsing object of the document.
[0044] S52, perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area.
[0045] In some feasible implementations, after determining the original DOM tree of the document to be browsed, the DOM tree can be traversed at least once, and the nodes traversed in each node traversal process can be copied to the target DOM tree corresponding to the document display area.
[0046] The target DOM tree is an object model used to represent the content of the webpage displayed in the document display area in a tree structure. It defines the structure, style, and content of the document displayed in the document display area. In other words, the webpage displayed in the document display area is generated based on the target DOM tree corresponding to the document display area.
[0047] When performing at least one node traversal on the original DOM tree, the nodes can be traversed according to the browsing order of the document content, based on the structural information of the original DOM tree.
[0048] Each node traversal process visits at least one node, and each node corresponds to a document element in the document to be viewed.
[0049] Each node traversal process visits a preset number of nodes, which is equivalent to visiting a preset number of document elements. Alternatively, the first node traversal process starts from the root node and continues until the node corresponding to the specific document element is reached. The second and subsequent node traversals also start from the node where the previous traversal process ended and continue until the node corresponding to the specific document element is reached.
[0050] S53, generate at least one page based on the document elements corresponding to the nodes added during each node traversal of the target DOM tree.
[0051] In some feasible implementations, after each node traversal of the original DOM tree, the nodes traversed in this node traversal process can be copied to the target DOM tree corresponding to the document display area, and at least one page can be generated based on the document elements corresponding to all the nodes added in the target DOM tree during this node traversal process.
[0052] In this process, the document elements corresponding to the nodes traversed in each node traversal constitute the document content of at least one page. Each node traversal corresponds to an independent page generation process; that is, after each node traversal of the original DOM tree, a page corresponding to the nodes traversed in that traversal is generated. In other words, after each node traversal, at least one page is generated, and each page is used to display the document content consisting of the document elements corresponding to a portion of the nodes traversed in that traversal.
[0053] For each node traversal process, when generating at least one page based on the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal, it is necessary to perform element preprocessing on the corresponding document elements, that is, to perform element processing such as scaling, layout, mapping, and rendering on the corresponding document elements so that the corresponding document elements match the pages in the document display area.
[0054] In some feasible implementations, each node traversal process of the original DOM tree in step S52 is a preorder traversal process.
[0055] The first node traversal starts at the root node of the original DOM tree, while the starting node for each subsequent node traversal is the node following the last node obtained in the previous traversal.
[0056] Based on this, it can be determined that the document content generated in each node traversal process does not include duplicate content, and the document content generated in each node traversal process is consistent with the browsing order of the document to be browsed.
[0057] Preorder traversal is a depth-first traversal method that follows a left-to-right traversal order. When traversing any DOM tree using preorder traversal, you can start from the root node of the DOM tree. This root node is usually a top-level element of the document, such as a `` or a specific container element.
[0058] Furthermore, after traversing the root node, it is necessary to determine the child nodes of the root node. If the root node has child nodes, when traversing the child nodes, it is necessary to traverse the first child node, then the second child node, and so on, until all child nodes have been visited.
[0059] For each child node, the same traversal method described above is used. After traversing the child node, it is determined whether the child node has any more children. Once all the child nodes of a child node have been visited, the recursive call ends, and the program returns to the parent node to continue traversing other unprocessed child nodes.
[0060] In other words, for each node in the DOM tree, the preorder traversal function needs to be called recursively, using that child node as the new root node for traversal. This recursive call repeats the access and traversal process until all child nodes have been traversed.
[0061] See Figure 6 , Figure 6 This is a schematic diagram illustrating the node traversal principle provided in an embodiment of this application. For example... Figure 6 As shown, during the first node traversal of the original DOM tree, nodes A1, A2, and A5 in the original DOM tree are traversed based on the preorder traversal method. Then, nodes A1, A2, and A5 in the original DOM tree can be copied to the target DOM tree. That is, the target DOM tree corresponding to the explicit area of the document is constructed based on nodes A1, A2, and A5 in the original DOM tree.
[0062] Furthermore, during the second node traversal of the original DOM tree, the traversal starts from node A3 based on the preorder traversal method, and traverses nodes A3, A6, and A7 in the original DOM tree. This allows nodes A3, A6, and A7 in the original DOM tree to be copied to the target DOM tree, forming the target DOM tree composed of nodes A1, A2, A3, A5, A6, and A7.
[0063] Furthermore, during the final node traversal of the original DOM tree, the traversal starts from node A4 based on the preorder traversal method, and traverses nodes A4, A8, and A9 in the original DOM tree. This allows nodes A4, A8, and A9 in the original DOM tree to be copied to the target DOM tree, forming the target DOM tree composed of nodes A1-A9.
[0064] In each of the aforementioned node traversals, the node traversal and copying processes are carried out simultaneously; that is, after each node is traversed, the node is copied to the target DOM tree.
[0065] In some feasible implementations, the document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in a page. That is, each node traversal process ultimately generates a page of document content based on the newly added nodes in the target DOM tree.
[0066] In this case, for each node traversal process, after each node is traversed, the traversed node is copied to the target DOM tree, and it is determined whether the length of the first content of the first document reaches the display height of the document display area.
[0067] The first document content comprises the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. Furthermore, the first document content is obtained after processing the document elements corresponding to the nodes through scaling, layout, mapping, rendering, and other element manipulation procedures. For example, ... Figure 6 During the first node traversal in the target DOM tree, if node A3 is reached, the document content consisting of the document elements corresponding to all newly added nodes (A1-A3) during this node traversal is determined as the first content length.
[0068] Furthermore, if it is determined that the length of the first content of the first document reaches the display height of the document display area, then it can be determined that the first document content can fill the document display area, that is, it can generate a complete page of document content, and thus the current node traversal process can be ended. For example, as follows Figure 6 During the first node traversal, if the length of the first content of the first document reaches the display height of the document display area when node A3 is traversed, it can be determined that the document content consisting of the newly added (A1-A3) document elements in the target DOM tree can fill the page, and the first node traversal process ends.
[0069] If the length of the first content in the first document does not reach the display height of the document display area, continue the current node traversal process until the length of the first content reaches the display height of the document display area. For example, ... Figure 6 During the first node traversal, if the length of the first content of the first document does not reach the display height of the document display area when node A2 is reached, the node traversal process can continue. If node A3 is reached and the length of the first content of the first document reaches the display height of the document display area, it can be determined that the document content consisting of the newly added (A1-A3) document elements in the target DOM tree can fill the page, and the first node traversal process ends.
[0070] Alternatively, continue the current node traversal process until there are no untraversed nodes in the original DOM tree before the length of the first content reaches the display height of the document display area, at which point the current node traversal process ends. For example, such as Figure 6 During the last node traversal in the DOM tree, if the length of the first content of the first document does not reach the display height of the document display area when node A9 is traversed, since there are no untraversed nodes in the original DOM tree, it can be determined that the document content consisting of the document elements corresponding to the newly added (A4, A8, and A9) in the target DOM tree is the last page content of the document to be viewed, and the last node traversal process ends.
[0071] In some feasible implementations, since the document element corresponding to a node in the original DOM tree is usually a small part of the content of a page of document, in order to improve the node traversal process, at the beginning of each node traversal process, N nodes are traversed first, and the traversed N nodes are copied to the target DOM tree, and then it is determined whether the length of the first content of the first document reaches the display height of the document display area.
[0072] The first document content refers to the document content consisting of all document elements corresponding to newly added nodes in the target DOM tree during this node traversal. Specifically, the first document content determined at the beginning of each node traversal is the document content obtained after scaling, formatting, mapping, rendering, and other element processing procedures on the document elements corresponding to the first N nodes traversed in this node traversal.
[0073] Where N is an integer greater than 1.
[0074] For example, such as Figure 6 In the first node traversal, assuming N is 2, nodes A1 and A2 are traversed first, and nodes A1 and A2 are copied to the target DOM tree. Then, the document content consisting of the document elements corresponding to all newly added nodes (A1 and A2) in the target DOM tree during this node traversal is determined as the first content length.
[0075] Furthermore, if it is determined that the length of the first content of the first document reaches the display height of the document display area, then it can be determined that the content of the first document can fill the document display area, that is, it can generate a complete page of document content, and thus the node traversal process can be ended.
[0076] If the length of the first content in the first document does not reach the display height of the document display area, continue the current node traversal process until the length of the first content reaches the display height of the document display area. For example, ... Figure 6 In the first node traversal, assuming N is 2 and nodes A1 and A2 have already been traversed, we continue traversing node A3. After copying node A3 to the target DOM tree and generating the first document content based on the document elements corresponding to nodes A1-A3, we determine whether the length of the first content of the first document reaches the display height of the document display area. If the length of the first content of the first document reaches the display height of the document display area, it can be determined that the document content consisting of the newly added document elements (A1-A3) in the target DOM tree can fill the page, and the first node traversal process ends.
[0077] Alternatively, if it is determined that the length of the first content of the first document does not reach the display height of the document display area, the current node traversal process continues until there are no untraversed nodes in the original DOM tree where the length of the first content does not reach the display height of the document display area, at which point the current node traversal process ends. For example, ... Figure 6 During the last node traversal in the DOM tree, if the length of the first content of the first document does not reach the display height of the document display area when node A9 is traversed, since there are no untraversed nodes in the original DOM tree, it can be determined that the document content consisting of the document elements corresponding to the newly added (A4, A8, and A9) in the target DOM tree is the last page content of the document to be viewed, and the last node traversal process ends.
[0078] In some feasible implementations, the document elements corresponding to the nodes traversed in each node traversal process constitute the document content of at least one page. That is, each node traversal process ultimately generates at least one page of document content based on the newly added nodes in the target DOM tree.
[0079] In this case, for each node traversal process, after traversing M nodes, the traversed nodes are copied to the target DOM tree, and it is determined whether the length of the first content of the first document reaches the display height of the document display area.
[0080] The first document content consists of the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. Furthermore, the first document content is obtained after processing the document elements corresponding to the nodes through scaling, layout, mapping, rendering, and other element manipulation procedures.
[0081] Furthermore, if the length of the first content of the first document is determined to be an integer multiple of the display height of the document display area, then it can be determined that the first document content can fill at least one page, that is, it can generate at least one complete page of document content, and thus the current node traversal process can be ended.
[0082] If the length of the first content of the first document is not an integer multiple of the display height of the document display area, continue traversing M nodes until the length of the first content reaches an integer multiple of the display height of the document display area. Alternatively, continue traversing M nodes until there are no untraversed nodes in the original DOM tree where the length of the first content has not reached the display height of the document display area, at which point the current node traversal process ends.
[0083] Based on the above implementation method, the number of nodes traversed in each node traversal process can be increased, so that each node traversal can generate one or more pages of document content, thereby improving the efficiency of document loading and generation while improving the efficiency of node traversal.
[0084] In some feasible implementations, for each node traversal process after the first node traversal process, when determining the first content length, the second content length of the second document content and the third content length of the fourth document content can be determined first, and then the length difference between the third content length and the second content length can be determined as the first content length.
[0085] The second document content consists of the document elements corresponding to all newly added nodes in the target DOM tree before this node traversal process. In other words, the length of the second content is the total length of all document content generated in the target DOM tree before this node traversal process, and this length does not include the length of the first document content.
[0086] The third document content is the document content composed of the document elements of all newly added nodes during the traversal of all nodes in the target DOM tree. In other words, the length of the third content is the total length of the document content generated based on all current nodes in the target DOM tree, which includes the length of the first content of the first document content.
[0087] The second and third document contents are both document contents obtained by scaling, formatting, mapping, rendering and other element processing of the document elements corresponding to the respective nodes.
[0088] Based on the second content length of the second document content and the third content length of the third document content, it is possible to accurately determine whether the document content corresponding to the node traversed in this node traversal process reaches the area height of the document display area.
[0089] In some feasible implementations, when displaying the document content of any page, if the document content of that page includes document content of a specified type, the document content of that type can be specified based on a preset display method.
[0090] The specified document content includes, but is not limited to, hyperlinks, phone numbers, email addresses, postal codes, specified names, preset keywords, etc. The specific content can be determined based on the actual application scenario requirements and is not restricted here.
[0091] Different types of document content can correspond to different preset display methods or the same preset display method. The specific method can be determined based on the actual application scenario requirements, and there are no restrictions here.
[0092] The aforementioned preset display methods can also be determined based on the actual application scenario requirements, such as highlighting, displaying based on preset colors, marking, etc., and are not limited here.
[0093] The following is combined with Figure 7 The display process of any page is further explained. Assume that each node traversal of the original DOM tree generates a page to display the document content of the document to be viewed. In any subsequent node traversal (except the last one) after determining the original DOM tree of the document to be viewed, after traversing one or a certain number of nodes, the traversed nodes are copied to the target DOM tree to determine the first document content, and it is determined whether the length of the first content of the first document reaches the display height of the document display area.
[0094] The first document content consists of the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. The first document content is also the document content obtained after scaling, layout, mapping, rendering and other element processing of the document elements corresponding to the corresponding nodes.
[0095] Furthermore, if it is determined that the length of the first content of the first document reaches the display height of the document display area, then it can be determined that the content of the first document can fill the document display area, that is, it can generate a complete page of document content, and thus the node traversal process can be ended.
[0096] If the length of the first content of the first document does not reach the display height of the document display area, continue the node traversal process until the length of the first content reaches the display height of the document display area.
[0097] Furthermore, after the current node traversal process is completed, the document content generated based on the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal can be used as a single page of document content and displayed in the document display area.
[0098] When displaying the document content of any page, if the document content of that page includes document content of a specified type, the document content of that type can be specified based on a preset display method.
[0099] In some feasible implementations, during the pagination display of the document content to be viewed in the document display area, in response to an editing trigger operation on the document to be viewed, the document content to be viewed is paginated in the text editing area.
[0100] In this case, when the entire content of the document to be viewed has been viewed in the document display area, the page used to display the document content in the document editing area is generated based on the following method: Perform at least one node pruning operation on the original DOM tree. Each node pruning process is used to prune all nodes traversed in one node traversal process, and the execution order of node pruning is consistent with the execution order of node traversal.
[0101] In other words, the first node pruning process prunes the nodes traversed in the first node traversal process from the original DOM tree, the second node pruning process prunes the nodes traversed in the second node traversal process from the original DOM tree, and so on, until the last node pruning process prunes the nodes traversed in the last node traversal process from the original DOM tree.
[0102] Furthermore, the nodes obtained in each node trimming process are concatenated to the edit DOM tree corresponding to the document editing area, and then at least one page is generated based on the document elements corresponding to the nodes added in each node trimming process in the edit DOM tree.
[0103] The process of displaying document content in the document editing area can also be implemented based on the WebView component.
[0104] See Figure 8 , Figure 8 This is one of the schematic diagrams of the node clipping process provided in the embodiments of this application. Assume the original DOM tree of the document to be browsed is as follows: Figure 8 As shown, this includes nodes B1-B8. Assuming that during the first node traversal, nodes B1, B2, and B5 are copied from the original DOM tree to the target DOM tree, then the first node pruning process prunes nodes B1, B2, and B5 from the original DOM tree to the edited DOM tree. That is, it prunes nodes B1, B2, and B5 from the original DOM tree and constructs the edited DOM tree based on the pruned nodes.
[0105] At this point, the original DOM tree only includes nodes B3, B4, B6, B7, and B8.
[0106] See Figure 9 , Figure 9 This is the second schematic diagram of the node trimming process provided in the embodiments of this application. After... Figure 8 After the node pruning process shown, the original DOM tree only includes nodes B3, B4, B6, B7, and B8. Assuming that nodes B3, B6, and B7 are copied from the original DOM tree to the target DOM tree during the second node traversal, the second node pruning process will prune nodes B3, B6, and B7 from the original DOM tree to the edited DOM tree. At this time, the edited DOM tree includes nodes B1-B3 and B5-B7, while the original DOM tree only includes nodes B4 and B8.
[0107] See Figure 10 , Figure 10 This is the third schematic diagram of the node trimming process provided in the embodiments of this application. After... Figure 9 After the node pruning process shown, the original DOM tree includes nodes B4 and B8. Assuming that nodes B4 and B8 are copied from the original DOM tree to the target DOM tree during the third node traversal, the third node pruning process will prune all remaining nodes (nodes B4 and B8) from the original DOM tree to the edit DOM tree. At this point, the edit DOM tree is the same as the original DOM tree, and the document can be displayed in the document editing area based on the edit DOM tree.
[0108] Optionally, if the document content of the document to be viewed has not been fully viewed in the document display area, the page used to display the document content in the document editing area is generated based on the following method: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and trim or copy the nodes traversed in each node traversal process to the edited DOM tree corresponding to the document editing area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. Generate at least one page based on the document elements corresponding to the nodes added during each node traversal of the DOM tree.
[0109] In other words, if the document content in the document display area has not been fully viewed, each page of document content needs to be displayed in the document editing area based on node traversal. Furthermore, the implementation method for paginating the document content in the document editing area is the same as the implementation method for paginating the document content in the document display area.
[0110] Specifically, in response to an edit trigger operation on the document to be viewed, the first page of the document content of the document to be viewed can be generated and displayed in the document editing area.
[0111] Furthermore, during document browsing based on the document editing area, in response to page-turning trigger operations, the document content of the next page of the document to be browsed corresponding to the current page can be generated and displayed in the document display area.
[0112] Optionally, in response to an editing trigger operation on the document to be viewed, the first page of the document content to be viewed can be generated and displayed in the document display area. During the browsing of the first page of the document content based on the document editing area, the content of each subsequent page of the document can be generated, and then in response to a page-turning trigger operation on any page, the content of the next page of the document to be viewed corresponding to the current page can be displayed in the document editing area.
[0113] Optionally, in response to an editing trigger operation on the document to be viewed, the first H pages of the document content to be viewed can be generated, and the first page of the document content to be viewed can be displayed in the document display area. During the browsing of the first H-1 pages based on the document editing area, in response to a page-turning trigger operation, the next page of the document content to be viewed can be displayed in the document editing area. At the same time, during the browsing of the first H pages of the document content, the content of each page after page H can be generated, and then when browsing to page H of the document content, in response to a page-turning trigger operation, the next page of the document content after page H can be displayed in the document display area, and the page-turning display of the document content can be realized during the flow of the document content on any page after page H.
[0114] Where H can be an integer greater than 1.
[0115] Based on the above pagination display method, the loading time of the document editing area for the document to be viewed can be shortened, thereby enabling the document to be viewed to be displayed quickly and improving document processing efficiency.
[0116] In some feasible implementations, the above-mentioned editing trigger operation is used to trigger relevant operations for editing the document to be viewed, such as relevant operations obtained based on the touch buttons of the document being edited. The specific operation can be determined based on the actual application scenario requirements and is not limited here.
[0117] See Figure 11 , Figure 11 This is one of the schematic diagrams illustrating a scenario for triggering document editing provided in an embodiment of this application. For example... Figure 11 As shown, assuming the document to be viewed is a large email, when receiving and forwarding a large email, the complete email content often won't be displayed. If editing the email is needed, it must be done via the relevant touch buttons on the email forwarding interface. For example, via... Figure 11 When the "Edit Original" touch button is activated, it indicates that the content of a large email needs to be edited. In this case, the touch operation can be considered an edit trigger, which will then display the content of the large email in pages. Or, as... Figure 12 , Figure 12 This is the second schematic diagram of a scenario for triggering document editing provided in this application embodiment. Similarly, when through... Figure 12 When the touch button "Load Full Email" is pressed, it indicates that the content of a large email needs to be edited. In this case, the touch operation can be regarded as an editing trigger operation, which will then display the content of the large email in pages.
[0118] In some feasible implementations, during the process of displaying document content through the document editing area, in response to a content editing operation on any page of document content, the nodes of the editing DOM tree are updated according to the content editing operation, and then the edited document content is displayed in the document editing area according to the updated editing DOM tree.
[0119] Specifically, updating nodes in the editable DOM tree based on content editing operations can be done by updating nodes in the editable DOM tree based on the operation position corresponding to the content editing operation and the edited content corresponding to the content editing operation.
[0120] The above-mentioned content editing operations include, but are not limited to, content deletion, content addition, and document format change operations. The specific operations can be determined based on the actual application scenario requirements and are not limited here.
[0121] As an example, when the content editing operation includes content deletion, the node in the editing DOM tree that matches the document element corresponding to the operation position can be determined based on the operation position of the content editing operation. Then, the node can be deleted from the editing DOM tree or the document element represented by the node can be updated according to the deleted content, thus realizing node update.
[0122] As an example, when content editing operations include content addition, the node in the editable DOM tree that matches the document element at the operation location can be determined based on the operation location. Then, the document element represented by that node can be updated according to the added content, thus achieving node updating. Alternatively, based on the operation location and the added document element, a node matching the added document element can be added at the corresponding position in the editable DOM tree, achieving node updating for the editable DOM tree.
[0123] In some feasible implementations, as the document editing area continuously generates and displays the content of each page of document according to the browsing or editing progress, a document forwarding operation can be initiated, and the current edited DOM tree and the current original DOM tree can be determined. The current edited DOM tree includes nodes pruned or copied from the original DOM tree and / or nodes that have been updated, while the current original DOM tree includes nodes that have not been pruned or traversed. The document content formed by the document elements corresponding to the nodes in the current edited DOM tree and the document elements corresponding to the nodes in the current original DOM tree constitutes the document content that needs to be forwarded.
[0124] In this case, the edited DOM tree and the original DOM tree can be concatenated to obtain the target DOM tree. Then, the target document can be generated based on the target DOM tree, and the target document can be sent according to the document forwarding operation to achieve the forwarding of document content.
[0125] As an example, see Figure 13 , Figure 13 This is a schematic diagram illustrating a scenario for forwarding documents provided in an embodiment of this application. For example... Figure 13 As shown, when the first page of document content is displayed in the document editing area, a document forwarding operation (such as clicking send) can be initiated. Since the current editing DOM tree only includes nodes corresponding to the first page of document content, the original DOM tree includes nodes other than those corresponding to the first page of document content. At this time, the editing DOM tree and the original DOM tree can be concatenated to obtain the target DOM tree. Then, the target document, i.e. the email document to be forwarded, is generated based on the target DOM tree. The target document is then sent according to the document forwarding operation, thus realizing the forwarding of document content.
[0126] Further integration Figure 14 As shown, Figure 14 This is a schematic diagram illustrating the generation of the target DOM tree through an embodiment of this application. For example... Figure 14 As shown, assuming a response to an edit trigger operation on the document to be viewed displays the first page of the document in the document editing area, the edit DOM tree corresponding to the document editing area includes nodes B1, B2, and B5, while the remaining nodes in the original DOM tree do not include nodes B1, B2, and B5. If a document forwarding operation is detected, the edit DOM tree and the original DOM tree can be concatenated to obtain a target DOM tree including all nodes B1-B8. The target document is then generated based on the target DOM tree, thus completing the forwarding of the target document.
[0127] In some feasible implementations, if a document forwarding operation is detected before the document content is displayed in the document editing area, the document to be browsed can be forwarded directly, that is, the target document can be generated directly based on the original DOM tree, and then the target document can be forwarded.
[0128] In some feasible implementations, the size of the content display area when the sender of the document to be viewed is inputting the document content is larger than the size of the document display area and the content editing area. That is, the size of the content display area when an object edits and generates the document to be viewed is larger than the size of the document display area and the content editing area.
[0129] For example, object A edits a document to be viewed on a computer and sends the document to object B. Object B obtains the document to be viewed through a mobile phone and, based on the document processing method provided in this application embodiment, displays the document to be viewed in pages in the document display area and content editing area on the mobile phone.
[0130] The display of the document content in different areas of the document display area and the content editing area is achieved by performing element preprocessing on the document elements, that is, scaling, layout, mapping, rendering and other element processing on the corresponding document elements.
[0131] This helps ensure that document content is displayed correctly in document display areas and content editing areas of different sizes, thus improving the document browsing experience.
[0132] In this embodiment, by traversing the original DOM tree of the document to be browsed and copying the traversed nodes to the target DOM tree to generate paginated content, not only can long documents be flexibly divided into multiple easy-to-read and manage pages, but also the page lag or crash caused by loading a large amount of content at once can be reduced, reducing page rendering pressure, thereby improving the reading experience and document loading efficiency.
[0133] Furthermore, since the document processing method provided in this application is based on the DOM tree, it can support various complex document formats and interactive requirements. Whether a document contains a large amount of text, images, tables, or multimedia elements such as videos, this technical solution can perform paginated display and processing, further improving document processing efficiency.
[0134] Meanwhile, since nodes in the editable DOM tree corresponding to the document editing area can be directly pruned from the original DOM tree, the construction time of the editable DOM tree can be reduced, thereby improving the display efficiency of the document editing area. Editing the DOM tree also allows for the flexible segmentation of long documents into multiple easily readable and manageable pages, and reduces page lag or crashes caused by loading large amounts of content at once, thus improving document editing efficiency.
[0135] Based on the document processing method provided in the embodiments of this application, documents with large amounts of data can be quickly loaded and displayed on small-screen devices such as mobile terminals and wearable devices, and the document content can be adapted to the display area, thereby improving the document reading experience.
[0136] See Figure 15 , Figure 15 This is a diagram illustrating the comparison of document loading times provided in an embodiment of this application. For example... Figure 15 As shown, before adopting the document processing method provided in this application embodiment, the traditional document processing method renders the entire original DOM tree of the document to be browsed, and then displays all the document content after obtaining it, resulting in a long document loading time (in seconds). However, after adopting the document processing method provided in this application embodiment, the loading and display time of documents with different data volumes is significantly reduced compared to the traditional document processing method, greatly improving the document loading efficiency.
[0137] See Figure 16 , Figure 16 This is a schematic diagram comparing rendering times provided in an embodiment of this application. For example... Figure 16 As shown, traditional document processing methods (before optimization) render the entire original DOM tree of the document to be viewed, resulting in a generally long rendering time (in seconds) for the first page. After sampling the document processing method provided in this application's embodiment (after optimization), since the content of each page is generated based on the document elements corresponding to a subset of nodes, the rendering time for the first page is significantly reduced. Similarly, see... Figure 17 , Figure 17 This is a diagram illustrating the time consumption for retrieving edited content provided in an embodiment of this application. For example... Figure 17 As shown, traditional document processing methods (before optimization) also require copying the original DOM tree to the editable DOM tree and rendering the entire tree when displaying document content in the document editing area. Therefore, traditional methods also require a relatively long time (in seconds) to load document content in the document editing area. After sampling the document processing method provided in the embodiments of this application (after optimization), since the document content of each page in the document editing area is generated by rendering document elements corresponding to some nodes in the editable DOM tree, and the nodes in the editable DOM tree can be directly pruned from the original DOM tree, the loading time of the document content in the document editing area is significantly shortened.
[0138] See Figure 18 , Figure 18 This is a schematic diagram of the structure of the document processing apparatus provided in the embodiments of this application. The document processing apparatus provided in the embodiments of this application includes: Document transfer module 181 is used to acquire the document to be viewed; The document display module 182 is used to display the document content of the document to be viewed in pages in the document display area in response to the browsing trigger operation; The page used to display document content in the aforementioned document display area is generated by the aforementioned document display module 182 in the following manner: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the newly added nodes during each node traversal of the target DOM tree.
[0139] In some feasible implementations, each node traversal process is a preorder traversal process; The starting node of the first node traversal is the root node of the original DOM tree, and the starting node of each subsequent node traversal is the node following the last node obtained in the previous node traversal.
[0140] In some feasible implementations, the document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in a page; the aforementioned document explicit module 182 is used for: After each node is traversed, the traversed node is copied to the target DOM tree. It is determined whether the length of the first content of the first document reaches the display height of the document display area. The first document content is the document content composed of the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. The current node traversal process ends when the length of the first content reaches the display height of the document display area. In response to the fact that the length of the first content has not reached the display height, the current node traversal process continues until the length of the first content reaches the display height, at which point the current node traversal process ends; or the current node traversal process continues until the original DOM tree has no untraversed nodes when the length of the first content has not reached the display height, at which point the current node traversal process ends.
[0141] In some feasible implementations, for each node traversal process after the first node traversal process, when the document explicit module 182 determines the length of the first content, it is used to: Determine the second content length of the second document content, which is the document content consisting of all the document elements corresponding to the newly added nodes in the target DOM tree before this node traversal process; Determine the length of the third document content. The third document content is the document content consisting of the document elements corresponding to all newly added nodes during the traversal of all nodes in the target DOM tree. The length difference between the length of the third content and the length of the second content is determined as the length of the first content.
[0142] In some feasible implementations, when the document display module 182 displays the document content of the document to be viewed in a paginated manner in the document display area, it is used to: In response to a browsing trigger, generate and display the first page of the document to be viewed in the document display area; During document browsing, in response to page turning triggers, the document content corresponding to the next page of the current page of the document to be browsed is generated and displayed in the document display area.
[0143] In some feasible implementations, the document explicit module 182 described above is also used for: In response to the editing trigger operation of the above-mentioned document to be viewed, the document content of the above-mentioned document to be viewed is displayed in pages in the document editing area; The page used to display document content in the aforementioned document editing area is generated based on the following method: Perform at least one node pruning on the original DOM tree. Each node pruning process is used to prune all nodes traversed in one node traversal process, and the execution order of node pruning is consistent with the execution order of node traversal. The nodes obtained from each node trimming process are concatenated to the editable DOM tree corresponding to the document editing area mentioned above. At least one page is generated based on the document elements corresponding to the newly added nodes in each node pruning process of the DOM tree described above.
[0144] In some feasible implementations, the document explicit module 182 described above is also used for: In response to a content editing operation on any page of the document within the document editing area, the nodes of the edit DOM tree are updated according to the content editing operation. Based on the updated edit DOM tree, the edited document content is displayed in the document editing area mentioned above.
[0145] In some feasible implementations, the document explicit module 182 described above is also used for: In response to the document forwarding operation, the edited DOM tree and the original DOM tree are concatenated to obtain the target DOM tree; The aforementioned document transfer module 181 is also used for: The target document is generated based on the target DOM tree described above, and then sent according to the document forwarding operation described above.
[0146] In some feasible implementations, the size of the content display area of the document to be viewed when the recipient enters the document content is larger than the size of the document display area and the content editing area.
[0147] In some feasible implementations, the document display module 182, when displaying the document content of any page, is further configured to: In response to the document content on this page including document content of a specified type, the document content of the specified type is displayed based on the preset display method.
[0148] In specific implementation, the aforementioned document processing device can perform the above-described actions through its built-in functional modules. Figure 2 and / or Figure 5 The implementation methods provided for each step are detailed in the above-mentioned implementation methods and will not be repeated here.
[0149] See Figure 19 , Figure 19 This is a schematic diagram of the structure of the electronic device provided in an embodiment of this application. For example... Figure 19 As shown, the electronic device 1900 in this embodiment may include: a processor 1901, a network interface 1904, and a memory 1905. Furthermore, the electronic device 1900 may also include: an object interface 1903, and at least one communication bus 1902. The communication bus 1902 is used to implement communication between these components. The object interface 1903 may include a display screen and a keyboard; optionally, the object interface 1903 may also include a standard wired interface or a wireless interface. The network interface 1904 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1905 may be a high-speed RAM or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory 1905 may also be at least one storage device located remotely from the aforementioned processor 1901. Figure 19 As shown, the memory 1905, which is a computer-readable storage medium, may include an operating system, a network communication module, an object interface module, and a device control application program.
[0150] exist Figure 19 In the illustrated electronic device 1900, the network interface 1904 provides network communication functionality; the object interface 1903 is primarily used to provide an input interface for objects; and the processor 1901 can be used to call the device control application program stored in the memory 1905 to achieve: Get the document to be viewed; In response to the browsing trigger operation, the document content of the document to be browsed is displayed in pages in the document display area; The pages used to display document content in the aforementioned document display area are generated based on the following method: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the newly added nodes during each node traversal of the target DOM tree.
[0151] In some feasible implementations, each node traversal process is a preorder traversal process; The starting node of the first node traversal is the root node of the original DOM tree, and the starting node of each subsequent node traversal is the node following the last node obtained in the previous node traversal.
[0152] In some feasible implementations, the document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in a page; the processor 1901 is used for: After each node is traversed, the traversed node is copied to the target DOM tree. It is determined whether the length of the first content of the first document reaches the display height of the document display area. The first document content is the document content composed of the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. The current node traversal process ends when the length of the first content reaches the display height of the document display area. In response to the fact that the length of the first content has not reached the display height, the current node traversal process continues until the length of the first content reaches the display height, at which point the current node traversal process ends; or the current node traversal process continues until the original DOM tree has no untraversed nodes when the length of the first content has not reached the display height, at which point the current node traversal process ends.
[0153] In some feasible implementations, for each node traversal process after the first node traversal process, when the processor 1901 determines the length of the first content, it is used to: Determine the second content length of the second document content, which is the document content consisting of all the document elements corresponding to the newly added nodes in the target DOM tree before this node traversal process; Determine the length of the third document content. The third document content is the document content consisting of the document elements corresponding to all newly added nodes during the traversal of all nodes in the target DOM tree. The length difference between the length of the third content and the length of the second content is determined as the length of the first content.
[0154] In some feasible implementations, when the processor 1901 displays the document content of the document to be viewed in a paginated manner in the document display area, it is used to: In response to a browsing trigger, generate and display the first page of the document to be viewed in the document display area; During document browsing, in response to page turning triggers, the document content corresponding to the next page of the current page of the document to be browsed is generated and displayed in the document display area.
[0155] In some feasible implementations, the processor 1901 is further configured to: In response to the editing trigger operation of the above-mentioned document to be viewed, the document content of the above-mentioned document to be viewed is displayed in pages in the document editing area; The page used to display document content in the aforementioned document editing area is generated based on the following method: Perform at least one node pruning on the original DOM tree. Each node pruning process is used to prune all nodes traversed in one node traversal process, and the execution order of node pruning is consistent with the execution order of node traversal. The nodes obtained from each node trimming process are concatenated to the editable DOM tree corresponding to the document editing area mentioned above. At least one page is generated based on the document elements corresponding to the newly added nodes in each node pruning process of the DOM tree described above.
[0156] In some feasible implementations, the processor 1901 is further configured to: In response to a content editing operation on any page of the document within the document editing area, the nodes of the edit DOM tree are updated according to the content editing operation. Based on the updated edit DOM tree, the edited document content is displayed in the document editing area mentioned above.
[0157] In some feasible implementations, the processor 1901 is further configured to: In response to the document forwarding operation, the edited DOM tree and the original DOM tree are concatenated to obtain the target DOM tree; The target document is generated based on the target DOM tree described above, and then sent according to the document forwarding operation described above.
[0158] In some feasible implementations, the size of the content display area of the document to be viewed when the recipient enters the document content is larger than the size of the document display area and the content editing area.
[0159] In some feasible implementations, when displaying the document content of any page, the processor 1901 is further configured to: In response to the document content on this page including document content of a specified type, the specified document content is displayed based on a preset display method. It should be understood that in some feasible implementations, the processor 1901 described above may be a central processing unit (CPU), which may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor. The memory may include read-only memory and random access memory, and provides instructions and data to the processor. A portion of the memory may also include non-volatile random access memory. For example, the memory may also store device type information.
[0160] In specific implementation, the aforementioned electronic device 1900 can perform the above-described actions through its built-in functional modules. Figure 2 and / or Figure 5 The implementation methods provided for each step are detailed in the above-mentioned implementation methods and will not be repeated here.
[0161] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to implement... Figure 2 and / or Figure 5 The methods provided in each step are detailed in the implementation methods provided in the above steps, and will not be repeated here.
[0162] The aforementioned computer-readable storage medium can be an internal storage unit of the document processing apparatus or electronic device provided in any of the foregoing embodiments, such as a hard disk or memory of the electronic device. The computer-readable storage medium can also be an external storage device of the electronic device, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device. The aforementioned computer-readable storage medium can also include magnetic disks, optical disks, read-only memory (ROM), or random access memory (RAM), etc. Furthermore, the computer-readable storage medium can include both internal storage units and external storage devices of the electronic device. The computer-readable storage medium is used to store the computer program and other programs and data required by the electronic device. The computer-readable storage medium can also be used to temporarily store data that has been output or will be output.
[0163] This application provides a computer program product, which includes a computer program that is executed by a processor. Figure 2 and / or Figure 5 The methods provided for each step in the process.
[0164] The terms "first," "second," etc., used in the claims, description, and drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or electronic device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or electronic devices. References to "embodiment" herein mean that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The presentation of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The term "and / or" as used in this application's description and appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0165] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Those skilled in the art can implement the described functions using different methods for each specific application, but such implementations should not be considered beyond the scope of this application.
[0166] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A document processing method, characterized in that, The method includes: Get the document to be viewed; In response to a browsing trigger operation, the document content of the document to be browsed is displayed in pages in the document display area; The page used to display document content in the document display area is generated based on the following method: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the nodes added during each node traversal of the target DOM tree.
2. The method according to claim 1, characterized in that, Each node traversal process is a preorder traversal process; The starting node of the first node traversal is the root node of the original DOM tree, and the starting node of each subsequent node traversal is the node following the last node obtained in the previous node traversal.
3. The method according to claim 1 or 2, characterized in that, The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in a page. Each node traversal process includes: After each node is traversed, the traversed node is copied to the target DOM tree. It is determined whether the length of the first content of the first document reaches the display height of the document display area. The first document content is the document content composed of the document elements corresponding to all newly added nodes in the target DOM tree during this node traversal. The node traversal process ends when the length of the first content reaches the display height of the document display area. In response to the first content length not reaching the display height, the current node traversal process continues until the first content length reaches the display height, at which point the current node traversal process ends; or the current node traversal process continues until the original DOM tree has no untraversed nodes when the first content length has not reached the display height, at which point the current node traversal process ends.
4. The method according to claim 3, characterized in that, For each subsequent node traversal after the first traversal, the length of the first content is determined, including: Determine the second content length of the second document content, where the second document content is the document content consisting of all document elements corresponding to newly added nodes in the target DOM tree before this node traversal process; Determine the length of the third document content, whereby the third document content is the document content consisting of the document elements corresponding to all newly added nodes during the traversal of all nodes in the target DOM tree; The length difference between the third content length and the second content length is determined as the first content length.
5. The method according to claim 1, characterized in that, The step of paginating the document content of the document to be viewed in the document display area includes: In response to a browsing trigger, generate and display the first page content of the document to be browsed in the document display area; During document content browsing, in response to a page-turning trigger operation, the document content corresponding to the next page of the current page of the document to be browsed is generated and displayed in the document display area.
6. The method according to claim 1, characterized in that, The method further includes: In response to an edit-triggered operation on the document to be viewed, the document content of the document to be viewed is displayed in pages in the document editing area; The page used to display document content in the document editing area is generated based on the following method: The original DOM tree is pruned at least once. Each pruning process is used to prune all nodes traversed in one node traversal process, and the execution order of node pruning is consistent with the execution order of node traversal. The nodes obtained in each node trimming process are concatenated to the edit DOM tree corresponding to the document editing area; At least one page is generated based on the document elements corresponding to the newly added nodes in each node pruning process of the DOM tree.
7. The method according to claim 6, characterized in that, The method further includes: In response to a content editing operation on any page of the document within the document editing area, the nodes of the edit DOM tree are updated according to the content editing operation; The edited document content is displayed in the document editing area based on the updated edit DOM tree.
8. The method according to claim 6 or 7, characterized in that, The method further includes: In response to a document forwarding operation, the edited DOM tree and the original DOM tree are concatenated to obtain the target DOM tree; The target document is generated based on the target DOM tree, and the target document is sent according to the document forwarding operation.
9. The method according to claim 1 or 7, characterized in that, The size of the content display area of the document to be viewed when the recipient enters the document content is larger than the size of the document display area and the content editing area.
10. The method according to claim 1 or 5, characterized in that, When displaying the document content of any page, the method further includes: In response to the document content on this page including document content of a specified type, the document content of the specified type is displayed based on the preset display method.
11. A document processing apparatus, characterized in that, The device includes: The document transfer module is used to acquire the document to be viewed; The document display module is used to display the document content of the document to be viewed in pages in the document display area in response to the browsing trigger operation; The page used to display document content in the document display area is generated by the document display module in the following way: Determine the original Document Object Model (DOM) tree of the document to be browsed; Perform at least one node traversal on the original DOM tree, and copy the nodes traversed in each node traversal process to the target DOM tree corresponding to the document display area. The document elements corresponding to the nodes traversed in each node traversal process constitute the document content included in at least one page. At least one page is generated based on the document elements corresponding to the nodes added during each node traversal of the target DOM tree.
12. An electronic device, characterized in that, It includes a processor and a memory, which are interconnected; The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 10 when the computer program is invoked.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to implement the method of any one of claims 1 to 10.
14. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 10.