#ifndef IOS_WEB_ANNOTATIONS_ANNOTATIONS_TEXT_MANAGER_IMPL_H_
#define IOS_WEB_ANNOTATIONS_ANNOTATIONS_TEXT_MANAGER_IMPL_H_
#import <UIKit/UIKit.h>
#import "base/memory/raw_ptr.h"
#import "base/observer_list.h"
#import "base/values.h"
#import "ios/web/public/annotations/annotations_text_manager.h"
#import "ios/web/public/web_state_observer.h"
#import "ios/web/public/web_state_user_data.h"
@protocol CRWWebViewHandlerDelegate;
namespace web {
class AnnotationsTextObserver;
class WebState;
* Class in charge of annotations in text.
*/
class AnnotationsTextManagerImpl : public AnnotationsTextManager,
public WebStateObserver {
public:
explicit AnnotationsTextManagerImpl(WebState* web_state);
~AnnotationsTextManagerImpl() override;
void AddObserver(AnnotationsTextObserver* observer) override;
void RemoveObserver(AnnotationsTextObserver* observer) override;
void DecorateAnnotations(WebState* web_state,
base::Value& annotations,
int seq_id) override;
void RemoveDecorations() override;
void RemoveDecorationsWithType(const std::string& type) override;
void RemoveHighlight() override;
void SetSupportedTypes(NSTextCheckingType supported_types) override;
void OnTextExtracted(WebState* web_state,
const std::string& text,
int seq_id,
const base::Value::Dict& metadata);
void OnDecorated(WebState* web_state,
int annotations,
int successes,
int failures,
const base::Value::List& cancelled);
void OnClick(WebState* web_state,
const std::string& text,
CGRect rect,
const std::string& data);
void PageLoaded(WebState* web_state,
PageLoadCompletionStatus load_completion_status) override;
void WebStateDestroyed(WebState* web_state) override;
private:
friend class WebStateUserData<AnnotationsTextManagerImpl>;
void StartExtractingText();
base::ObserverList<AnnotationsTextObserver, true> observers_;
raw_ptr<WebState> web_state_ = nullptr;
int seq_id_;
bool is_viewport_extraction_;
NSTextCheckingType supported_types_ = 0;
base::WeakPtrFactory<AnnotationsTextManagerImpl> weak_factory_{this};
};
}
#endif