Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: chrome/renderer/form_manager.h

Issue 2138005: AutoFill: Preview form field values when the user changes the AutoFill dropdown (Closed)
Patch Set: Rebase. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/renderer/form_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_FORM_MANAGER_H_ 5 #ifndef CHROME_RENDERER_FORM_MANAGER_H_
6 #define CHROME_RENDERER_FORM_MANAGER_H_ 6 #define CHROME_RENDERER_FORM_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 11 matching lines...) Expand all
22 class WebFrame; 22 class WebFrame;
23 } // namespace WebKit 23 } // namespace WebKit
24 24
25 // Manages the forms in a RenderView. 25 // Manages the forms in a RenderView.
26 class FormManager { 26 class FormManager {
27 public: 27 public:
28 // A bit field mask for form requirements. 28 // A bit field mask for form requirements.
29 enum RequirementsMask { 29 enum RequirementsMask {
30 REQUIRE_NONE = 0x0, // No requirements. 30 REQUIRE_NONE = 0x0, // No requirements.
31 REQUIRE_AUTOCOMPLETE = 0x1, // Require that autocomplete != off. 31 REQUIRE_AUTOCOMPLETE = 0x1, // Require that autocomplete != off.
32 REQUIRE_ELEMENTS_ENABLED = 0x2 // Require that disabled attribute is off. 32 REQUIRE_ENABLED = 0x2, // Require that disabled attribute is off.
33 REQUIRE_EMPTY = 0x4, // Require that the fields are empty.
33 }; 34 };
34 35
35 FormManager(); 36 FormManager();
36 virtual ~FormManager(); 37 virtual ~FormManager();
37 38
38 // Fills out a FormField object from a given WebFormControlElement. 39 // Fills out a FormField object from a given WebFormControlElement.
39 // If |get_value| is true, |field| will have the value set from |element|. 40 // If |get_value| is true, |field| will have the value set from |element|.
40 static void WebFormControlElementToFormField( 41 static void WebFormControlElementToFormField(
41 const WebKit::WebFormControlElement& element, 42 const WebKit::WebFormControlElement& element,
42 bool get_value, 43 bool get_value,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 RequirementsMask requirements, 85 RequirementsMask requirements,
85 webkit_glue::FormData* form); 86 webkit_glue::FormData* form);
86 87
87 // Fills the form represented by |form|. |form| should have the name set to 88 // Fills the form represented by |form|. |form| should have the name set to
88 // the name of the form to fill out, and the number of elements and values 89 // the name of the form to fill out, and the number of elements and values
89 // must match the number of stored elements in the form. 90 // must match the number of stored elements in the form.
90 // TODO(jhawkins): Is matching on name alone good enough? It's possible to 91 // TODO(jhawkins): Is matching on name alone good enough? It's possible to
91 // store multiple forms with the same names from different frames. 92 // store multiple forms with the same names from different frames.
92 bool FillForm(const webkit_glue::FormData& form); 93 bool FillForm(const webkit_glue::FormData& form);
93 94
95 // Previews the form represented by |form|. Same conditions as FillForm.
96 bool PreviewForm(const webkit_glue::FormData& form);
97
98 // Clears the placeholder values and the auto-filled background for any fields
99 // in |form| that have been previewed.
100 void ClearPreviewedForm(const webkit_glue::FormData& form);
101
94 // Fills all of the forms in the cache with form data from |forms|. 102 // Fills all of the forms in the cache with form data from |forms|.
95 void FillForms(const std::vector<webkit_glue::FormData>& forms); 103 void FillForms(const std::vector<webkit_glue::FormData>& forms);
96 104
97 // Resets the stored set of forms. 105 // Resets the stored set of forms.
98 void Reset(); 106 void Reset();
99 107
100 // Resets the forms for the specified |frame|. 108 // Resets the forms for the specified |frame|.
101 void ResetFrame(const WebKit::WebFrame* frame); 109 void ResetFrame(const WebKit::WebFrame* frame);
102 110
103 private: 111 private:
(...skipping 23 matching lines...) Expand all
127 // Infers corresponding label for |element| from surrounding context in the 135 // Infers corresponding label for |element| from surrounding context in the
128 // DOM. Contents of preceding <p> tag or preceding text element found in 136 // DOM. Contents of preceding <p> tag or preceding text element found in
129 // the form. 137 // the form.
130 static string16 InferLabelForElement( 138 static string16 InferLabelForElement(
131 const WebKit::WebFormControlElement& element); 139 const WebKit::WebFormControlElement& element);
132 140
133 // Uses the data in |form| to find the cached FormElement. 141 // Uses the data in |form| to find the cached FormElement.
134 bool FindCachedFormElement(const webkit_glue::FormData& form, 142 bool FindCachedFormElement(const webkit_glue::FormData& form,
135 FormElement** form_element); 143 FormElement** form_element);
136 144
137 // For each field in |form| that matches the corresponding field in the cached 145 // For each field in |data| that matches the corresponding field in |form|
138 // FormElement, |callback| is called with the actual WebFormControlElement and 146 // and meets the |requirements|, |callback| is called with the actual
139 // the FormField data from |form|. This method owns |callback|. 147 // WebFormControlElement and the FormField data from |form|. This method owns
148 // |callback|.
140 void ForEachMatchingFormField(FormElement* form, 149 void ForEachMatchingFormField(FormElement* form,
150 RequirementsMask requirements,
141 const webkit_glue::FormData& data, 151 const webkit_glue::FormData& data,
142 Callback* callback); 152 Callback* callback);
143 153
144 // A ForEachMatchingFormField() callback that sets |field|'s value using the 154 // A ForEachMatchingFormField() callback that sets |field|'s value using the
145 // value in |data|. 155 // value in |data|. This method also sets the autofill attribute, causing the
156 // background to be yellow.
146 void FillFormField(WebKit::WebFormControlElement* field, 157 void FillFormField(WebKit::WebFormControlElement* field,
147 const webkit_glue::FormField* data); 158 const webkit_glue::FormField* data);
148 159
160 // A ForEachMatchingFormField() callback that sets |field|'s placeholder value
161 // using the value in |data|, causing the test to be greyed-out. This method
162 // also sets the autofill attribute, causing the background to be yellow.
163 void PreviewFormField(WebKit::WebFormControlElement* field,
164 const webkit_glue::FormField* data);
165
149 // The map of form elements. 166 // The map of form elements.
150 WebFrameFormElementMap form_elements_map_; 167 WebFrameFormElementMap form_elements_map_;
151 168
152 DISALLOW_COPY_AND_ASSIGN(FormManager); 169 DISALLOW_COPY_AND_ASSIGN(FormManager);
153 }; 170 };
154 171
155 #endif // CHROME_RENDERER_FORM_MANAGER_H_ 172 #endif // CHROME_RENDERER_FORM_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/form_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698